Class: Representable::Config
- Inherits:
-
Inheritable::Hash
- Object
- Hash
- Inheritable::Hash
- Representable::Config
- Extended by:
- Forwardable
- Defined in:
- lib/representable/config.rb
Overview
Config contains three independent, inheritable directives: features, options and definitions. It is a hash - just add directives if you need them.
You may access/alter the property Definitions using #each, #collect, #add, #get.
-
features, [options]: “horizontally”+“vertically” inherited values (inline representer)
-
definitions, [options], wrap: “vertically” inherited (class inheritance, module inclusion)
Inheritance works via Config#inherit!(parent).
Defined Under Namespace
Classes: Definitions
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #features ⇒ Object
-
#initialize(definition_class = Definition) ⇒ Config
constructor
A new instance of Config.
-
#wrap=(value) ⇒ Object
#collect comes from Hash and then gets delegated to @definitions.
-
#wrap_for(name, context, *args) ⇒ Object
Computes the wrap string or returns false.
Methods included from Inheritable::Hash::InstanceMethods
Constructor Details
#initialize(definition_class = Definition) ⇒ Config
Returns a new instance of Config
54 55 56 57 58 59 60 61 |
# File 'lib/representable/config.rb', line 54 def initialize(definition_class=Definition) super() merge!( :features => @features = Inheritable::Hash.new, :definitions => @definitions = Definitions.new(definition_class), :options => @options = Inheritable::Hash.new, :wrap => nil ) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options
62 63 64 |
# File 'lib/representable/config.rb', line 62 def @options end |
Instance Method Details
#features ⇒ Object
64 65 66 |
# File 'lib/representable/config.rb', line 64 def features @features.keys end |
#wrap=(value) ⇒ Object
#collect comes from Hash and then gets delegated to @definitions. don't like that.
73 74 75 76 |
# File 'lib/representable/config.rb', line 73 def wrap=(value) value = value.to_s if value.is_a?(Symbol) self[:wrap] = Uber::Options::Value.new(value) end |
#wrap_for(name, context, *args) ⇒ Object
Computes the wrap string or returns false.
79 80 81 82 83 84 85 86 |
# File 'lib/representable/config.rb', line 79 def wrap_for(name, context, *args) return unless self[:wrap] value = self[:wrap].evaluate(context, *args) return infer_name_for(name) if value === true value end |