Module: Origami::StandardObject::ClassMethods
- Defined in:
- lib/origami/object.rb
Overview
:nodoc:all
Instance Method Summary collapse
- #define_field_methods(field) ⇒ Object
- #field(name, attributes) ⇒ Object
- #fields ⇒ Object
- #hint_type(name) ⇒ Object
- #inherited(subclass) ⇒ Object
-
#required_fields ⇒ Object
Returns an array of required fields for the current Object.
Instance Method Details
#define_field_methods(field) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/origami/object.rb', line 136 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
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/origami/object.rb', line 122 def field(name, attributes) if attributes[:Required] == true and attributes.has_key?(:Default) and attributes[:Type] == Name self.add_type_info(self, name, attributes[:Default]) end if not @fields.has_key?(name) @fields[name] = attributes else @fields[name].merge! attributes end define_field_methods(name) end |
#fields ⇒ Object
118 119 120 |
# File 'lib/origami/object.rb', line 118 def fields @fields end |
#hint_type(name) ⇒ Object
158 159 160 161 162 |
# File 'lib/origami/object.rb', line 158 def hint_type(name) if @fields.has_key?(name) @fields[name][:Type] end end |
#inherited(subclass) ⇒ Object
114 115 116 |
# File 'lib/origami/object.rb', line 114 def inherited(subclass) subclass.instance_variable_set(:@fields, Marshal.load(Marshal.dump(@fields))) end |
#required_fields ⇒ Object
Returns an array of required fields for the current Object.
149 150 151 152 153 154 155 156 |
# File 'lib/origami/object.rb', line 149 def required_fields fields = [] @fields.each_pair { |name, attributes| fields << name if attributes[:Required] == true } fields end |