Module: Origami::StandardObject::ClassMethods

Includes:
TypeGuessing
Defined in:
lib/origami/object.rb

Overview

:nodoc:all

Instance Method Summary collapse

Methods included from TypeGuessing

#guess_type

Instance Method Details

#field(name, attributes) ⇒ Object

Define a new field with given attributes.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/origami/object.rb', line 184

def field(name, attributes)
    if attributes[:Required] and attributes.key?(:Default) and attributes[:Type] == Name
        signature = {}
        signature[name] = attributes[:Default]

        add_type_signature(**signature)
    end

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

    define_field_methods(name)
end

#fieldsObject



177
178
179
# File 'lib/origami/object.rb', line 177

def fields
    @fields
end

#hint_type(name) ⇒ Object

Returns the expected type for a field name.



216
217
218
# File 'lib/origami/object.rb', line 216

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

#inherited(subclass) ⇒ Object



173
174
175
# File 'lib/origami/object.rb', line 173

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.



204
205
206
207
208
209
210
211
# File 'lib/origami/object.rb', line 204

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

    fields
end