Class: Hako::Schema::Structure

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/schema/structure.rb

Instance Method Summary collapse

Constructor Details

#initializeStructure

Returns a new instance of Structure.



6
7
8
# File 'lib/hako/schema/structure.rb', line 6

def initialize
  @members = {}
end

Instance Method Details

#member(key, schema) ⇒ Object



32
33
34
# File 'lib/hako/schema/structure.rb', line 32

def member(key, schema)
  @members[key] = schema
end

#same?(x, y) ⇒ Boolean

Returns:



23
24
25
26
27
28
29
30
# File 'lib/hako/schema/structure.rb', line 23

def same?(x, y)
  @members.each do |key, val_schema|
    unless val_schema.same?(x[key], y[key])
      return false
    end
  end
  true
end

#valid?(object) ⇒ Boolean

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hako/schema/structure.rb', line 10

def valid?(object)
  unless object.is_a?(::Hash)
    return false
  end

  @members.each do |key, val_schema|
    unless val_schema.valid?(object[key])
      return false
    end
  end
  true
end