Class: Showcase::Helpers::ConfigObject

Inherits:
Object
  • Object
show all
Defined in:
lib/showcase/helpers/config_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, &block) ⇒ ConfigObject

Returns a new instance of ConfigObject.



6
7
8
9
# File 'lib/showcase/helpers/config_object.rb', line 6

def initialize(context, &block)
  @config_block = block
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



21
22
23
24
# File 'lib/showcase/helpers/config_object.rb', line 21

def method_missing(name, *args, &block)
  name = name.to_s.gsub(/=$/, '')
  @result[name.to_sym] = args.first
end

Instance Method Details

#to_hashObject



15
16
17
18
19
# File 'lib/showcase/helpers/config_object.rb', line 15

def to_hash
  @result = {}
  @context.instance_exec(self, &@config_block)
  @result.symbolize_keys
end

#to_structObject



11
12
13
# File 'lib/showcase/helpers/config_object.rb', line 11

def to_struct
  OpenStruct.new(to_hash)
end