Class: Schai::JsRoot

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schemaObject

Returns the value of attribute schema.



3
4
5
# File 'lib/schai/json_schema/js_root.rb', line 3

def schema
  @schema
end

Class Method Details

.parse(params) ⇒ Object



5
6
7
8
9
# File 'lib/schai/json_schema/js_root.rb', line 5

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

.parse_components(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/schai/json_schema/js_root.rb', line 11

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'
    JsObject.parse params
  when params['type'] == 'array'
    JsArray.parse params
  when !params.has_key?('type')
    raise "typeは必須(#{params})"
  else
    JsProperty.parse params
  end
end

Instance Method Details

#to_schemaObject



31
32
33
34
35
36
# File 'lib/schai/json_schema/js_root.rb', line 31

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