Module: RVC::ObjectWithFields::ClassMethods

Included in:
InventoryObject, InventoryObject::ClassMethods
Defined in:
lib/rvc/field.rb

Instance Method Summary collapse

Instance Method Details

#field(name, &b) ⇒ Object



38
39
40
41
42
# File 'lib/rvc/field.rb', line 38

def field name, &b
  name = name.to_s
  @fields ||= {}
  @fields[name] = RVC::Field.new(name).tap { |f| f.instance_eval &b }
end

#fields(inherited = true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/rvc/field.rb', line 27

def fields inherited=true
  @fields ||= {}
  if inherited
    ancestors.select { |x| x.respond_to? :fields }.
              map { |x| x.fields(false) }.
              reverse.inject({}) { |b,v| b.merge v }
  else
    @fields
  end
end