Class: WsdlMapper::Generation::DefaultFormatter
- Inherits:
-
Object
- Object
- WsdlMapper::Generation::DefaultFormatter
- Defined in:
- lib/wsdl_mapper/generation/default_formatter.rb
Overview
Default implementation for the ruby formatter interface. This class should be considered as a reference for custom implementations. All public methods are mandatory.
Instance Method Summary (collapse)
- - (Object) assignment(var_name, value)
- - (Object) assignments(*assigns)
- - (Object) attr_accessors(*attrs)
- - (Object) attr_readers(*attrs)
- - (Object) begin_class(name)
- - (Object) begin_def(name, *args)
- - (Object) begin_module(name)
- - (Object) begin_modules(names)
- - (Object) begin_sub_class(name, super_name)
- - (Object) blank_comment
- - (Object) blank_line (also: #after_requires, #after_constants)
- - (Object) block(statement, block_args)
- - (Object) block_assignment(var_name, statement, block_args, &block)
- - (Object) call(name, *args)
- - (Object) end
- - (Object) end_modules(names)
- - (Object) in_class(name)
- - (Object) in_def(name, *args)
- - (Object) in_modules(names)
- - (Object) in_sub_class(name, super_name)
-
- (DefaultFormatter) initialize(io)
constructor
A new instance of DefaultFormatter.
- - (Object) literal_array(name, values)
- - (Object) literal_hash(name, key_values)
- - (Object) next_statement
- - (Object) require(path)
- - (Object) requires(*paths)
- - (Object) statement(statement)
- - (Object) statements(*statements)
Constructor Details
- (DefaultFormatter) initialize(io)
Returns a new instance of DefaultFormatter
6 7 8 9 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 6 def initialize(io) @io = io @i = 0 end |
Instance Method Details
- (Object) assignment(var_name, value)
190 191 192 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 190 def assignment(var_name, value) statement "#{var_name} = #{value}" end |
- (Object) assignments(*assigns)
194 195 196 197 198 199 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 194 def assignments(*assigns) assigns.each do |(var_name, value)| assignment var_name, value end blank_line end |
- (Object) attr_accessors(*attrs)
93 94 95 96 97 98 99 100 101 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 93 def attr_accessors(*attrs) return if attrs.empty? attrs = attrs.map { |a| ":#{a}" } attrs.each do |attr| statement "attr_accessor #{attr}" end blank_line end |
- (Object) attr_readers(*attrs)
30 31 32 33 34 35 36 37 38 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 30 def attr_readers(*attrs) return if attrs.empty? attrs = attrs.map { |a| ":#{a}" } attrs.each do |attr| statement "attr_reader #{attr}" end blank_line end |
- (Object) begin_class(name)
124 125 126 127 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 124 def begin_class(name) statement "class #{name}" inc_indent end |
- (Object) begin_def(name, *args)
146 147 148 149 150 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 146 def begin_def(name, *args) blank_line statement method_definition(name, args) inc_indent end |
- (Object) begin_module(name)
103 104 105 106 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 103 def begin_module(name) statement "module #{name}" inc_indent end |
- (Object) begin_modules(names)
108 109 110 111 112 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 108 def begin_modules(names) names.each do |name| begin_module name end end |
- (Object) begin_sub_class(name, super_name)
129 130 131 132 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 129 def begin_sub_class(name, super_name) statement "class #{name} < #{super_name}" inc_indent end |
- (Object) blank_comment
24 25 26 27 28 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 24 def blank_comment statement '#' @blank_line = true self end |
- (Object) blank_line Also known as: after_requires, after_constants
17 18 19 20 21 22 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 17 def blank_line # Prevent double blank lines append "\n" unless @blank_line @blank_line = true self end |
- (Object) block(statement, block_args)
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 64 def block(statement, block_args) indent buf = statement.dup buf << ' do' args = block_args.join ', ' buf << " |#{args}|" if block_args.any? @io << buf next_statement inc_indent yield self.end end |
- (Object) block_assignment(var_name, statement, block_args, &block)
77 78 79 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 77 def block_assignment(var_name, statement, block_args, &block) block "#{var_name} = #{statement}", block_args, &block end |
- (Object) call(name, *args)
56 57 58 59 60 61 62 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 56 def call(name, *args) if args.empty? statement name else statement "#{name}(#{args * ', '})" end end |
- (Object) end
201 202 203 204 205 206 207 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 201 def end dec_indent if @blank_line @io.seek -1, IO::SEEK_CUR end statement 'end' end |
- (Object) end_modules(names)
114 115 116 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 114 def end_modules(names) names.each { self.end } end |
- (Object) in_class(name)
134 135 136 137 138 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 134 def in_class(name) begin_class name yield self.end end |
- (Object) in_def(name, *args)
152 153 154 155 156 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 152 def in_def(name, *args) begin_def name, *args yield self.end end |
- (Object) in_modules(names)
118 119 120 121 122 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 118 def in_modules(names) begin_modules names yield end_modules names end |
- (Object) in_sub_class(name, super_name)
140 141 142 143 144 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 140 def in_sub_class(name, super_name) begin_sub_class name, super_name yield self.end end |
- (Object) literal_array(name, values)
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 158 def literal_array(name, values) if values.empty? statement "#{name} = []" return end statement "#{name} = [" inc_indent values[0..-2].each do |value| statement "#{value}," end statement values.last dec_indent statement ']' end |
- (Object) literal_hash(name, key_values)
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 174 def literal_hash(name, key_values) if key_values.empty? statement "#{name} = {}" return end statement "#{name} = {" inc_indent key_values[0..-2].each do |value| statement "#{value}," end statement key_values.last dec_indent statement '}' end |
- (Object) next_statement
11 12 13 14 15 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 11 def next_statement append "\n" @blank_line = false self end |
- (Object) require(path)
81 82 83 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 81 def require(path) statement "require #{path.inspect}" end |
- (Object) requires(*paths)
85 86 87 88 89 90 91 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 85 def requires(*paths) return unless paths.any? paths.each do |path| require path end after_requires end |
- (Object) statement(statement)
43 44 45 46 47 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 43 def statement(statement) indent @io << statement next_statement end |
- (Object) statements(*statements)
49 50 51 52 53 54 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 49 def statements(*statements) statements.each do |s| statement s end blank_line end |