Module: Origami::StandardObject::ClassMethods

Defined in:
lib/origami/object.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#define_field_methods(field) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/origami/object.rb', line 137

def define_field_methods(field)
  reader = lambda { obj = self[field]; obj.is_a?(Reference) ? obj.solve : obj }
  writer = lambda { |value| self[field] = value }
  set = lambda { |value| self[field] = value; self }
  
  send(:define_method, field.id2name, reader)
  send(:define_method, field.id2name + "=", writer)
  send(:define_method, "set" + field.id2name, set)  
end

#field(name, attributes) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/origami/object.rb', line 126

def field(name, attributes)

  if not @fields.has_key?(name)
    @fields[name] = attributes
  else
    @fields[name].merge! attributes
  end
  
  define_field_methods(name)
end

#fieldsObject



122
123
124
# File 'lib/origami/object.rb', line 122

def fields
  @fields
end

#inherited(subclass) ⇒ Object



118
119
120
# File 'lib/origami/object.rb', line 118

def inherited(subclass)
  subclass.instance_variable_set(:@fields, Marshal.load(Marshal.dump(@fields)))
end

#required_fieldsObject

Returns an array of required fields for the current Object.



150
151
152
153
154
155
156
157
# File 'lib/origami/object.rb', line 150

def required_fields
  fields = []
  @fields.each_pair { |name, attributes|
      fields << name if attributes[:Required] == true
  }

  fields
end