Module: AbstractMapper::Attributes::DSL

Defined in:
lib/abstract_mapper/attributes.rb

Overview

Attributes DSL

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ undefined

Declares the attribute

Options Hash (options):

  • :default (Object)


56
57
58
59
# File 'lib/abstract_mapper/attributes.rb', line 56

def attribute(name, options = {})
  attributes[name.to_sym] = options[:default]
  define_method(name) { attributes[name.to_sym] }
end

#attributesHash

Default attributes for the node



44
45
46
# File 'lib/abstract_mapper/attributes.rb', line 44

def attributes
  @attributes ||= {}
end

#inherited(klass) ⇒ Object

Makes a attributes inheritable



36
37
38
# File 'lib/abstract_mapper/attributes.rb', line 36

def inherited(klass)
  attributes.each { |key, value| klass.attribute key, default: value }
end