Class: Houston::HashDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHashDsl

Returns a new instance of HashDsl.



498
499
500
# File 'lib/configuration.rb', line 498

def initialize
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



510
511
512
513
514
515
516
517
518
# File 'lib/configuration.rb', line 510

def method_missing(method_name, *args, &block)
  if block_given?
    @hash[method_name] = HashDsl.hash_from_block(block)
  elsif args.length == 1
    @hash[method_name] = args.first
  else
    super
  end
end

Instance Attribute Details

#hashObject (readonly) Also known as: to_hash, to_h

Returns the value of attribute hash.



494
495
496
# File 'lib/configuration.rb', line 494

def hash
  @hash
end

Class Method Details

.from_block(block) ⇒ Object



502
503
504
# File 'lib/configuration.rb', line 502

def self.from_block(block)
  HashDsl.new.tap { |dsl| dsl.instance_eval(&block) }
end

.hash_from_block(block) ⇒ Object



506
507
508
# File 'lib/configuration.rb', line 506

def self.hash_from_block(block)
  from_block(block).to_hash
end