Class: Dimples::Metadata

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

Overview

A class representing metadata passed into a template for rendering.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Metadata

Returns a new instance of Metadata.



8
9
10
11
12
13
14
15
# File 'lib/dimples/metadata.rb', line 8

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

  @keys = source.keys
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_method_name, *_args) ⇒ Object



28
29
30
# File 'lib/dimples/metadata.rb', line 28

def method_missing(_method_name, *_args)
  nil
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



6
7
8
# File 'lib/dimples/metadata.rb', line 6

def keys
  @keys
end

Instance Method Details

#build(item) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/dimples/metadata.rb', line 17

def build(item)
  case item
  when Array
    item.map { |i| build(i) }
  when Hash
    item.empty? ? item : Metadata.new(item)
  else
    item
  end
end

#respond_to_missing?(_method_name, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(_method_name, _include_private)
  true
end