schai 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99670c33c4e1e826924ed5902a5d2143ab5fe033
4
- data.tar.gz: 779db26346971a87a519e5f33c4bfecb7103423a
3
+ metadata.gz: e440f870638d3ccde9bf0c8e8a8161aefb6bc533
4
+ data.tar.gz: 118a6e81d6fcd1d87daa32d8926fa27362357691
5
5
  SHA512:
6
- metadata.gz: a029ce8f1e7176b5c99ead8dec921d612cd33542f81b40f02167e874856d06a37d7ce28e1dd94968566fe0582fc2410a1191f42bd1142668a0c15d94b2dc3bd9
7
- data.tar.gz: 41d4eacd6480a70a29d645222a88a532130708fef0771faa5f7479711c7f0cb707e0371e6a902ee09768dd40712b003c83ff51651022d8ce237ca095b6337ef9
6
+ metadata.gz: f65464c07a36e7543dd865a58e1f7411c2e418e33e0265469e9fd95ac0b8129c063a838dcf965e246a3735fb9ccd83c82bef6a793a23214f7e31766fc2082abc
7
+ data.tar.gz: 2300fb30fcbc81a4869050d65e5fe9dc96501fe93314cd4ba0943c0be9435b7d622a7b38486ea77c13a865c92d9d85ea61076bce578ed7e1739da8f82a4e51e2
data/lib/schai.rb CHANGED
@@ -11,17 +11,24 @@ module Schai
11
11
  JsRoot.parse params
12
12
  end
13
13
 
14
- def self.parse_file path
14
+ def self.path
15
15
  @@path ||=[]
16
- if @@path.empty?
17
- @@path << path
16
+ end
17
+
18
+ def self.current_parsing_file? path
19
+ File.expand_path("../#{path}", Schai.path.last) == Schai.path.last
20
+ end
21
+
22
+ def self.parse_file path
23
+ if Schai.path.empty?
24
+ Schai.path << path
18
25
  ret = parse YAML.load_file(path)
19
- @@path.pop
26
+ Schai.path.pop
20
27
  else
21
- expand_path = File.expand_path("../#{path}", @@path.last)
22
- @@path << expand_path
28
+ expand_path = File.expand_path("../#{path}", Schai.path.last)
29
+ Schai.path << expand_path
23
30
  ret = parse YAML.load_file(expand_path)
24
- @@path.pop
31
+ Schai.path.pop
25
32
  end
26
33
  ret
27
34
  end
@@ -7,6 +7,10 @@ module Schai
7
7
  end
8
8
 
9
9
  def initialize params
10
+ params["properties"].select! do |k, e|
11
+ !(Schai.current_parsing_file?(e['include']) and e['optional'])
12
+ end
13
+
10
14
  @all = Hash[params["properties"].map {|k, v|
11
15
  [k || 'null', JsRoot.parse_components(v)]
12
16
  }]
@@ -3,26 +3,28 @@ module Schai
3
3
  attr_accessor :schema
4
4
 
5
5
  def self.parse params
6
- ret = self.new
7
- ret.schema = parse_components params
8
- ret
6
+ self.new.tap do |js_root|
7
+ js_root.schema = parse_components params
8
+ end
9
9
  end
10
10
 
11
11
  def self.parse_components params
12
- case
13
- when params.has_key?('include')
12
+ # include other .yaml file
13
+ if params.has_key?('include')
14
14
  included_schema = Schai.parse_file(params.delete('include')).schema
15
15
  params.each do |k, v|
16
16
  setter = "#{k}=".to_sym
17
17
  included_schema.send(setter, v)
18
18
  end
19
- included_schema
20
- when params['type'] == 'object'
19
+ return included_schema
20
+ end
21
+
22
+ raise "typeは必須(#{params})" unless params.has_key?('type')
23
+ case params['type']
24
+ when 'object'
21
25
  JsObject.parse params
22
- when params['type'] == 'array'
26
+ when 'array'
23
27
  JsArray.parse params
24
- when !params.has_key?('type')
25
- raise "typeは必須(#{params})"
26
28
  else
27
29
  JsProperty.parse params
28
30
  end
data/lib/schai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Schai
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gin0606
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor