Class: Liquid::Section
Overview
Am Configuration consists of one or more Sections. A section is a hash-like object that responds to all keys in the hash as if they were methods:
> s = Section.from_hash({:v1 => 2, :nested => {:v2 => 1}})
> s.v1
=> 2
> s.nested.v2
=> 1
Direct Known Subclasses
Class Attribute Summary collapse
-
.nil_action ⇒ Object
How to handle nil values in the configuration?.
Class Method Summary collapse
-
.from_hash(hsh) ⇒ Section
Create a new section from the given hash-like object.
Methods inherited from Hash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/liquid/configuration.rb', line 66 def method_missing(name, *args) if name.to_s =~ /(.*)=$/ self[$1.to_sym] = Section.from_value(args.first) else value = self[name] self[name] = value.call if value.is_a?(Proc) self[name] end end |
Class Attribute Details
.nil_action ⇒ Object
How to handle nil values in the configuration?
Possible values are:
- :nil, nil (return nil)
- :raise (raise an exception)
- :section (return a NilSection which can be chained)
32 33 34 |
# File 'lib/liquid/configuration.rb', line 32 def nil_action @nil_action end |
Class Method Details
.from_hash(hsh) ⇒ Section
Create a new section from the given hash-like object.
38 39 40 41 42 43 44 |
# File 'lib/liquid/configuration.rb', line 38 def from_hash(hsh) new.tap do |result| hsh.each do |key, value| result[key.to_sym] = from_value(value) end end end |