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
- #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 ⇒ Object (also: #after_requires, #after_constants)
- #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) ⇒ Object
-
#initialize(io) ⇒ DefaultFormatter
constructor
A new instance of DefaultFormatter.
- #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) ⇒ Object
Constructor Details
#initialize(io) ⇒ DefaultFormatter
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
#assignment(var_name, value) ⇒ Object
190 191 192 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 190 def assignment(var_name, value) statement "#{var_name} = #{value}" end |
#assignments(*assigns) ⇒ Object
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 |
#attr_accessors(*attrs) ⇒ Object
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 |
#attr_readers(*attrs) ⇒ Object
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 |
#begin_class(name) ⇒ Object
124 125 126 127 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 124 def begin_class(name) statement "class #{name}" inc_indent end |
#begin_def(name, *args) ⇒ Object
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 |
#begin_module(name) ⇒ Object
103 104 105 106 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 103 def begin_module(name) statement "module #{name}" inc_indent end |
#begin_modules(names) ⇒ Object
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 |
#begin_sub_class(name, super_name) ⇒ Object
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 |
#blank_comment ⇒ Object
24 25 26 27 28 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 24 def blank_comment statement '#' @blank_line = true self end |
#blank_line ⇒ Object 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 |
#block(statement, block_args) ⇒ Object
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 |
#block_assignment(var_name, statement, block_args, &block) ⇒ Object
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 |
#call(name, *args) ⇒ Object
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 |
#end ⇒ Object
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 |
#end_modules(names) ⇒ Object
114 115 116 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 114 def end_modules(names) names.each { self.end } end |
#in_class(name) ⇒ Object
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 |
#in_def(name, *args) ⇒ Object
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 |
#in_modules(names) ⇒ Object
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 |
#in_sub_class(name, super_name) ⇒ Object
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 |
#literal_array(name, values) ⇒ Object
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 |
#literal_hash(name, key_values) ⇒ Object
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 |
#next_statement ⇒ Object
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 |
#require(path) ⇒ Object
81 82 83 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 81 def require(path) statement "require #{path.inspect}" end |
#requires(*paths) ⇒ Object
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 |
#statement(statement) ⇒ Object
43 44 45 46 47 |
# File 'lib/wsdl_mapper/generation/default_formatter.rb', line 43 def statement(statement) indent @io << statement next_statement end |
#statements(*statements) ⇒ Object
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 |