Class: Mushikago::Hanamgri::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/mushikago/hanamgri/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Schema

Returns a new instance of Schema.



8
9
10
11
# File 'lib/mushikago/hanamgri/schema.rb', line 8

def initialize(&block)
  @fields = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



6
7
8
# File 'lib/mushikago/hanamgri/schema.rb', line 6

def fields
  @fields
end

Instance Method Details

#add(field_or_hash) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/mushikago/hanamgri/schema.rb', line 13

def add field_or_hash
  field = field_or_hash
  if field.kind_of?(Hash)
    field = Mushikago::Hanamgri::Field.new(field[:name], field[:required], field[:type], field[:knowledge_name])
  end
  field.validate!
  @fields << field
end

#to_json(*args) ⇒ Object



22
23
24
# File 'lib/mushikago/hanamgri/schema.rb', line 22

def to_json *args
  {:fields => @fields}.to_json(args)
end