prmd 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmYyYTg0MjRlYWQwZjBlZjFlMGU2OTVjODUyODYyZDQxOTZjMDgyNA==
4
+ ZGFhZTI3Yjc0OTA3ZWI5Mzc4NzBlNWQzMWY4YmQ5ZmRmNjAzZGIwMg==
5
5
  data.tar.gz: !binary |-
6
- MjNiZDJhNzdhMDU1M2MyYTNjOTViODgxMGJkZTMyNGY2YTRhODcwMg==
6
+ MTZlMzFjMDhjMWYyYmRlM2YxZjIyNjNkZjRjOWI0NmZkNDk4ZmU1MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmI5ZDU5ZTBkMGNmODQyYWNkYmY4Y2IxMTJlY2QxMGYwNTgyY2MwZDI0Njg0
10
- OTczYTU2ZDI0ODBjZTJkNGIxMTQwYTUwNDdkNzA5ZmMzNjM5ZTgyNzlmYzEy
11
- YjI3YmNiYjkxYzVlNmU3NDc1ZDQ1ZTMzZDliODZhZDcyNWI0NGU=
9
+ MDM1ZTE1MTI1YWNiMDMzZmQ4YmRhYzQ0MDI4Nzc4ZmI1ODM3NTUyODEzYjZm
10
+ YTY5NGU3Mjk1ZmVhZDQ3Mjg2OTMwZjA2NmRlYzc3OTNkNWEyOWZjYTM4NzI2
11
+ OWU5OTZjMTU4ZmNiYzUyMTg5NmE4NGM0MTgyN2QxMzFiNzEyMDY=
12
12
  data.tar.gz: !binary |-
13
- OTEyYTllYzkzODRkYWM3ODQ2NGM0MTA1Y2UyMjRiNDA4ZjMxZDUzMzI3YTRj
14
- MjQyYTc1NmMyMWJmZTY4MTMxMDQ0OWYxYjBlZTNkMmVhYjAyNGQ2Yzc1Njg4
15
- NjcyZWZiMGM0MTZhODc4Y2U1ZWNjNTIzNjFhOTQ1NzI4ZTZlN2I=
13
+ NjI0ZWJjOTRjNTA5YTM4MzI4NzI0ZDc2ZTYyZDQyNzRlYmM2MzIwOWQ2MDMy
14
+ NWVlYmExZDNhNTJiMDkxYmU5ZmRiNzRiZGNhYjA1NDUwZjcwOGQ0NDhhZmY0
15
+ Yjg4MDMwYmFlOWJkMDY0ZDljOTdiMWRhY2Q0NzA4ZmQ3YWFkMDU=
@@ -1,6 +1,7 @@
1
1
  * Brandur <brandur@mutelight.org>
2
2
  * Chris Continanza <christopher.continanza@gmail.com>
3
3
  * Dane Harrigan <dane.harrigan@gmail.com>
4
+ * Kousuke Ebihara <kousuke@co3k.org>
4
5
  * Mark McGranaghan <mmcgrana@gmail.com>
5
6
  * Olivier Lance <olance@users.noreply.github.com>
6
7
  * Timothée Peignier <timothee.peignier@tryphon.org>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prmd (0.1.0)
4
+ prmd (0.2.0)
5
5
  erubis (~> 2.7)
6
6
 
7
7
  GEM
data/bin/prmd CHANGED
@@ -19,6 +19,9 @@ commands = {
19
19
  end,
20
20
  init: OptionParser.new do |opts|
21
21
  opts.banner = "prmd init [options] <resource name>"
22
+ opts.on("-y", "--yaml", "Generate YAML") do |y|
23
+ options[:yaml] = y
24
+ end
22
25
  end,
23
26
  verify: OptionParser.new do |opts|
24
27
  opts.banner = "prmd verify [options] <combined schema>"
@@ -1,6 +1,7 @@
1
1
  require "cgi"
2
2
  require "erubis"
3
3
  require "json"
4
+ require "yaml"
4
5
 
5
6
  dir = File.dirname(__FILE__)
6
7
  require File.join(dir, 'prmd', 'commands', 'combine')
@@ -1,11 +1,14 @@
1
1
  module Prmd
2
2
  def self.combine(path, options={})
3
3
  files = if File.directory?(path)
4
- Dir.glob(File.join(path, '**', '*.json')) - [options[:meta]]
4
+ Dir.glob(File.join(path, '**', '*.json')) +
5
+ Dir.glob(File.join(path, '**', '*.yaml')) -
6
+ [options[:meta]]
5
7
  else
6
8
  [path]
7
9
  end
8
- schemas = files.map { |file| JSON.parse(File.read(file)) }
10
+ # sort for stable loading on any platform
11
+ schemas = files.sort.map { |file| [file, YAML.load(File.read(file))] }
9
12
 
10
13
  data = {
11
14
  '$schema' => 'http://json-schema.org/draft-04/hyper-schema',
@@ -14,16 +17,24 @@ module Prmd
14
17
  'type' => ['object']
15
18
  }
16
19
 
20
+ # tracks which entities where defined in which file
21
+ definitions_map = {}
22
+
17
23
  if options[:meta] && File.exists?(options[:meta])
18
- data.merge!(JSON.parse(File.read(options[:meta])))
24
+ data.merge!(YAML.load(File.read(options[:meta])))
19
25
  end
20
26
 
21
- schemas.each do |schema_data|
27
+ schemas.each do |schema_file, schema_data|
22
28
  id = if schema_data['id']
23
29
  schema_data['id'].split('/').last
24
30
  end
25
31
  next if id.nil? || id[0..0] == '_' # FIXME: remove this exception?
26
32
 
33
+ if file = definitions_map[id]
34
+ $stderr.puts "`#{id}` (from #{schema_file}) was already defined in `#{file}` and will overwrite the first definition"
35
+ end
36
+ definitions_map[id] = schema_file
37
+
27
38
  data['definitions'][id] = schema_data
28
39
  reference_localizer = lambda do |datum|
29
40
  case datum
@@ -102,6 +102,10 @@ module Prmd
102
102
  }
103
103
  end
104
104
 
105
- schema.to_s
105
+ if options[:yaml]
106
+ schema.to_yaml
107
+ else
108
+ schema.to_json
109
+ end
106
110
  end
107
111
  end
@@ -55,12 +55,20 @@ module Prmd
55
55
  end
56
56
  end
57
57
 
58
- def to_s
58
+ def to_json
59
59
  new_json = JSON.pretty_generate(@data)
60
60
  # nuke empty lines
61
61
  new_json = new_json.split("\n").delete_if {|line| line.empty?}.join("\n") + "\n"
62
62
  new_json
63
63
  end
64
64
 
65
+ def to_yaml
66
+ YAML.dump(@data)
67
+ end
68
+
69
+ def to_s
70
+ to_json
71
+ end
72
+
65
73
  end
66
74
  end
@@ -1,3 +1,3 @@
1
1
  module Prmd
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: prmd
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
  - geemus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-17 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis