class Representable::Config
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).
Attributes
options[R]
Public Class Methods
new(definition_class=Definition)
click to toggle source
Calls superclass method
# File lib/representable/config.rb, line 55 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
Public Instance Methods
features()
click to toggle source
# File lib/representable/config.rb, line 65 def features @features.keys end
wrap=(value)
click to toggle source
collect comes from Hash and then gets delegated to @definitions. don't like that.
# File lib/representable/config.rb, line 74 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) { || ... }
click to toggle source
Computes the wrap string or returns false.
# File lib/representable/config.rb, line 80 def wrap_for(name, context, *args, &block) return unless self[:wrap] value = self[:wrap].evaluate(context, *args) name = yield if block_given? # DISCUSS: deprecate/restructure the entire wrapping flow. return infer_name_for(name) if value === true value end
Private Instance Methods
infer_name_for(name)
click to toggle source
# File lib/representable/config.rb, line 92 def infer_name_for(name) name.to_s.split('::').last. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase end