Class: Schai::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/schai/hoge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schemaObject

Returns the value of attribute schema.



33
34
35
# File 'lib/schai/hoge.rb', line 33

def schema
  @schema
end

Class Method Details

.parse(params) ⇒ Object



35
36
37
38
39
# File 'lib/schai/hoge.rb', line 35

def self.parse params
  ret = self.new
  ret.schema = parse_components params
  ret
end

.parse_components(params) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/schai/hoge.rb', line 41

def self.parse_components params
  case
  when params.has_key?('include')
    included_schema = Schai.parse_file(params.delete('include')).schema
    params.each do |k, v|
      setter = "#{k}=".to_sym
      included_schema.send(setter, v)
    end
    included_schema
  when params['type'] == 'object'
    Object.parse params
  when params['type'] == 'array'
    Array.parse params
  when !params.has_key?('type')
    raise "typeは必須(#{params})"
  else
    Schai::Property.parse params
  end
end

Instance Method Details

#to_schemaObject



61
62
63
64
65
66
# File 'lib/schai/hoge.rb', line 61

def to_schema
  schema = {
    '$schema': "http://json-schema.org/draft-04/schema#"
  }
  schema.merge @schema.to_schema
end