Class: Gem::Release::Files::Template::Context::Const
- Inherits:
-
Struct
- Object
- Struct
- Gem::Release::Files::Template::Context::Const
- Defined in:
- lib/gem/release/files/template/context.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
Returns the value of attribute names.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
Instance Attribute Details
#names ⇒ Object
Returns the value of attribute names
6 7 8 |
# File 'lib/gem/release/files/template/context.rb', line 6 def names @names end |
#type ⇒ Object
Returns the value of attribute type
6 7 8 |
# File 'lib/gem/release/files/template/context.rb', line 6 def type @type end |
Instance Method Details
#build(names, &block) ⇒ Object
14 15 16 |
# File 'lib/gem/release/files/template/context.rb', line 14 def build(names, &block) names.map.with_index { |name, ix| indent(block.call(name), ix) } end |
#define(&block) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/gem/release/files/template/context.rb', line 7 def define(&block) lines = build(names) { |name| "#{type} #{name}" } lines << indent(block.call, names.size) if block lines += build(names) { |name| 'end' }.reverse lines.join("\n") end |
#indent(str, level) ⇒ Object
18 19 20 |
# File 'lib/gem/release/files/template/context.rb', line 18 def indent(str, level) "#{' ' * level}#{str}" end |