Class: Gem::Release::Files::Template::Context::Const

Inherits:
Struct
  • Object
show all
Defined in:
lib/gem/release/files/template/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#namesObject

Returns the value of attribute names

Returns:

  • (Object)

    the current value of names


6
7
8
# File 'lib/gem/release/files/template/context.rb', line 6

def names
  @names
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of 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