Class: Representable::Config

Inherits:
Inheritable::Hash show all
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

Instance Method Summary collapse

Methods included from Inheritable::Hash::InstanceMethods

#clone, #inherit!

Constructor Details

#initialize(definition_class = Definition) ⇒ Config

Returns a new instance of Config.



46
47
48
49
50
51
52
53
# File 'lib/representable/config.rb', line 46

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

#optionsObject (readonly)

Returns the value of attribute options.



54
55
56
# File 'lib/representable/config.rb', line 54

def options
  @options
end

Instance Method Details

#featuresObject



56
57
58
# File 'lib/representable/config.rb', line 56

def features
  @features.keys
end

#wrap=(value) ⇒ Object

#collect comes from Hash and then gets delegated to @definitions. don’t like that.



65
66
67
68
# File 'lib/representable/config.rb', line 65

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.



71
72
73
74
75
76
77
78
# File 'lib/representable/config.rb', line 71

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