Class: Representable::Config

Inherits:
Hash
  • Object
show all
Includes:
InheritMethods, InheritableArray
Defined in:
lib/representable/config.rb

Overview

NOTE: the API of Config is subject to change so don’t rely too much on this private object.

Defined Under Namespace

Modules: InheritMethods, InheritableArray

Instance Method Summary collapse

Methods included from InheritableArray

#inherit, #inheritable_array, #inheritable_arrays

Methods included from InheritMethods

#cloned, #inherit

Methods included from Hash

#from_hash, included, #to_hash

Instance Method Details

#<<(definition) ⇒ Object



22
23
24
# File 'lib/representable/config.rb', line 22

def <<(definition)
  self[definition.name] = definition
end

#[](name) ⇒ Object



26
27
28
# File 'lib/representable/config.rb', line 26

def [](name)
  fetch(name.to_s, nil)
end

#each(*args, &block) ⇒ Object



30
31
32
# File 'lib/representable/config.rb', line 30

def each(*args, &block)
  values.each(*args, &block)
end

#optionsObject

Write representer configuration into this hash.



50
51
52
# File 'lib/representable/config.rb', line 50

def options
  @options ||= {}
end

#wrap=(value) ⇒ Object



34
35
36
37
# File 'lib/representable/config.rb', line 34

def wrap=(value)
  value = value.to_s if value.is_a?(Symbol)
  @wrap = Uber::Options::Value.new(value)
end

#wrap_for(name, context, *args) ⇒ Object

Computes the wrap string or returns false.



40
41
42
43
44
45
46
47
# File 'lib/representable/config.rb', line 40

def wrap_for(name, context, *args)
  return unless @wrap

  value = @wrap.evaluate(context, *args)

  return infer_name_for(name) if value === true
  value
end