Class: Detroit::Toolchain::Script::BlockContext

Inherits:
Object
  • Object
show all
Defined in:
lib/detroit/toolchain/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&b) ⇒ BlockContext

Returns a new instance of BlockContext.



162
163
164
165
# File 'lib/detroit/toolchain/script.rb', line 162

def initialize(&b)
  @settings = {}
  b.arity == 1 ? b.call(self) : instance_eval(&b)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, value = nil, *args) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/detroit/toolchain/script.rb', line 179

def method_missing(symbol, value=nil, *args)
  case name = symbol.to_s
  when /=$/
    @settings[name.chomp('=')] = value
  else
    return super(symbol, value, *args) unless args.empty?
    if value
      @settings[name.to_s] = value
    else
      @settings[name.to_s]
    end
  end
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



159
160
161
# File 'lib/detroit/toolchain/script.rb', line 159

def settings
  @settings
end

Instance Method Details

#set(name, value = nil, &block) ⇒ Object



168
169
170
171
172
173
174
175
176
# File 'lib/detroit/toolchain/script.rb', line 168

def set(name, value=nil, &block)
  if block
    block_context = BlockContext.new
    block.call(block_context)
    @settings[name.to_s] = block_context.settings
  else
    @settings[name.to_s] = value
  end
end