Module: Origami::StandardObject::ClassMethods

Defined in:
lib/origami/object.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#field(name, attributes) ⇒ Object

Define a new field with given attributes.



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/origami/object.rb', line 138

def field(name, attributes)
    if attributes[:Required] == true and attributes.has_key?(:Default) and attributes[:Type] == Name
        self.add_type_signature(name, attributes[:Default])
    end

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

    define_field_methods(name)
end

#fieldsObject



131
132
133
# File 'lib/origami/object.rb', line 131

def fields
    @fields
end

#hint_type(name) ⇒ Object

Returns the expected type for a field name.



167
168
169
170
171
# File 'lib/origami/object.rb', line 167

def hint_type(name)
    if @fields.has_key?(name)
        @fields[name][:Type]
    end
end

#inherited(subclass) ⇒ Object



127
128
129
# File 'lib/origami/object.rb', line 127

def inherited(subclass)
    subclass.instance_variable_set(:@fields, Hash[@fields.map{|name, attributes| [name, attributes.clone]}])
end

#required_fieldsObject

Returns an array of required fields for the current Object.



155
156
157
158
159
160
161
162
# File 'lib/origami/object.rb', line 155

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

    fields
end