Class: Kaigara::Metadata
- Inherits:
-
Object
- Object
- Kaigara::Metadata
- Defined in:
- lib/kaigara/metadata.rb
Defined Under Namespace
Classes: DeepHash
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Here are all variables from metadata.rb.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Metadata
constructor
You can see how it works in
metadata.rb
. -
#method_missing(name, *args, &block) ⇒ Object
Returns a variable from @data.
Constructor Details
#initialize(&block) ⇒ Metadata
You can see how it works in metadata.rb
34 35 36 37 38 39 |
# File 'lib/kaigara/metadata.rb', line 34 def initialize(&block) hash = DeepHash.new # Here's a hook that changes variables storage class. block.call(hash) # We're passing this hash to initialize block (see metadata.rb example) json = hash.to_json # Then we changes the type of it to json, then to OpenStruct. @data = JSON.parse(json, object_class: OpenStruct) # Now we can use any variable as @var.l1.l2.l3.l4.l5 and so on end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Returns a variable from @data
44 45 46 |
# File 'lib/kaigara/metadata.rb', line 44 def method_missing(name, *args, &block) return @data.send(name) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Here are all variables from metadata.rb
29 30 31 |
# File 'lib/kaigara/metadata.rb', line 29 def data @data end |