Class: Representable::Config::Definitions

Inherits:
Inheritable::Hash show all
Extended by:
Forwardable
Defined in:
lib/representable/config.rb

Overview

Stores Definitions from ::property. It preserves the adding order (1.9+). Same-named properties get overridden, just like in a Hash.

Overwrite definition_class if you need a custom Definition object (helpful when using representable in other gems).

Instance Method Summary collapse

Methods included from Inheritable::Hash::InstanceMethods

#clone, #inherit!

Constructor Details

#initialize(definition_class) ⇒ Definitions



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

def initialize(definition_class)
  @definition_class = definition_class
  super()
end

Instance Method Details

#add(name, options, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/representable/config.rb', line 30

def add(name, options, &block)
  if options[:inherit] # i like that: the :inherit shouldn't be handled outside.
    return get(name).merge!(options, &block)
  end

  self[name.to_s] = definition_class.new(name, options, &block)
end

#get(name) ⇒ Object



38
39
40
# File 'lib/representable/config.rb', line 38

def get(name)
  self[name.to_s]
end

#remove(name) ⇒ Object



42
43
44
# File 'lib/representable/config.rb', line 42

def remove(name)
  delete(name.to_s)
end