Class: Dimples::Metadata

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dimples/metadata.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Metadata



5
6
7
8
9
10
11
12
# File 'lib/dimples/metadata.rb', line 5

def initialize(source)
  source.each do |key, value|
    self.class.send(:attr_reader, key)
    instance_variable_set("@#{key}", build(value))
  end

  @data = source
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args) ⇒ Object



30
31
32
33
34
# File 'lib/dimples/metadata.rb', line 30

def method_missing(method_name, *_args)
  return @data[method_name] if @data.key?(method_name)

  nil
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/dimples/metadata.rb', line 18

def [](key)
  @data[key]
end

#each(&block) ⇒ Object



22
23
24
# File 'lib/dimples/metadata.rb', line 22

def each(&block)
  @data.each(&block)
end

#each_key(&block) ⇒ Object



26
27
28
# File 'lib/dimples/metadata.rb', line 26

def each_key(&block)
  @data.keys.each(&block)
end

#keysObject



14
15
16
# File 'lib/dimples/metadata.rb', line 14

def keys
  @data.keys
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean



36
37
38
# File 'lib/dimples/metadata.rb', line 36

def respond_to_missing?(method_name, include_private = false)
  @data.key?(method_name) || super
end