jimmy 0.5.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.gitignore +4 -3
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +61 -0
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +6 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +13 -0
  10. data/LICENSE +1 -1
  11. data/README.md +22 -134
  12. data/Rakefile +91 -1
  13. data/bin/console +15 -0
  14. data/bin/setup +8 -0
  15. data/jimmy.gemspec +25 -21
  16. data/lib/jimmy.rb +23 -15
  17. data/lib/jimmy/declaration.rb +150 -0
  18. data/lib/jimmy/declaration/assertion.rb +81 -0
  19. data/lib/jimmy/declaration/casting.rb +34 -0
  20. data/lib/jimmy/declaration/composites.rb +41 -0
  21. data/lib/jimmy/declaration/number.rb +27 -0
  22. data/lib/jimmy/declaration/object.rb +11 -0
  23. data/lib/jimmy/declaration/string.rb +100 -0
  24. data/lib/jimmy/declaration/types.rb +57 -0
  25. data/lib/jimmy/error.rb +9 -0
  26. data/lib/jimmy/file_map.rb +166 -0
  27. data/lib/jimmy/index.rb +78 -0
  28. data/lib/jimmy/json/array.rb +93 -0
  29. data/lib/jimmy/json/collection.rb +90 -0
  30. data/lib/jimmy/json/hash.rb +118 -0
  31. data/lib/jimmy/json/pointer.rb +119 -0
  32. data/lib/jimmy/json/uri.rb +144 -0
  33. data/lib/jimmy/loaders/base.rb +30 -0
  34. data/lib/jimmy/loaders/json.rb +15 -0
  35. data/lib/jimmy/loaders/ruby.rb +21 -0
  36. data/lib/jimmy/macros.rb +37 -0
  37. data/lib/jimmy/schema.rb +106 -87
  38. data/lib/jimmy/schema/array.rb +95 -0
  39. data/lib/jimmy/schema/casting.rb +17 -0
  40. data/lib/jimmy/schema/json.rb +40 -0
  41. data/lib/jimmy/schema/number.rb +47 -0
  42. data/lib/jimmy/schema/object.rb +108 -0
  43. data/lib/jimmy/schema/operators.rb +96 -0
  44. data/lib/jimmy/schema/string.rb +44 -0
  45. data/lib/jimmy/schema_with_uri.rb +53 -0
  46. data/lib/jimmy/schemer_factory.rb +65 -0
  47. data/lib/jimmy/version.rb +3 -1
  48. data/schema07.json +172 -0
  49. metadata +50 -101
  50. data/circle.yml +0 -11
  51. data/lib/jimmy/combination.rb +0 -34
  52. data/lib/jimmy/definitions.rb +0 -38
  53. data/lib/jimmy/domain.rb +0 -111
  54. data/lib/jimmy/link.rb +0 -93
  55. data/lib/jimmy/reference.rb +0 -39
  56. data/lib/jimmy/schema_creation.rb +0 -121
  57. data/lib/jimmy/schema_type.rb +0 -100
  58. data/lib/jimmy/schema_types.rb +0 -42
  59. data/lib/jimmy/schema_types/array.rb +0 -30
  60. data/lib/jimmy/schema_types/boolean.rb +0 -6
  61. data/lib/jimmy/schema_types/integer.rb +0 -8
  62. data/lib/jimmy/schema_types/null.rb +0 -6
  63. data/lib/jimmy/schema_types/number.rb +0 -34
  64. data/lib/jimmy/schema_types/object.rb +0 -45
  65. data/lib/jimmy/schema_types/string.rb +0 -40
  66. data/lib/jimmy/symbol_array.rb +0 -17
  67. data/lib/jimmy/transform_keys.rb +0 -39
  68. data/lib/jimmy/type_reference.rb +0 -14
  69. data/lib/jimmy/validation_error.rb +0 -20
metadata CHANGED
@@ -1,126 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimmy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json-schema
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.5'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.5'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.9'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.9'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.2'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.2'
69
- - !ruby/object:Gem::Dependency
70
- name: diff_matcher
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.7'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '2.7'
83
- description: Jimmy makes it a snap to compose detailed JSON schema documents.
11
+ date: 2020-06-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Jimmy the Gem
84
14
  email:
85
- - neil.pearson@orionvm.com
15
+ - neil@helium.net.au
86
16
  executables: []
87
17
  extensions: []
88
18
  extra_rdoc_files: []
89
19
  files:
20
+ - ".circleci/config.yml"
90
21
  - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
91
24
  - ".ruby-version"
25
+ - ".travis.yml"
26
+ - CODE_OF_CONDUCT.md
92
27
  - Gemfile
93
28
  - LICENSE
94
29
  - README.md
95
30
  - Rakefile
96
- - circle.yml
31
+ - bin/console
32
+ - bin/setup
97
33
  - jimmy.gemspec
98
34
  - lib/jimmy.rb
99
- - lib/jimmy/combination.rb
100
- - lib/jimmy/definitions.rb
101
- - lib/jimmy/domain.rb
102
- - lib/jimmy/link.rb
103
- - lib/jimmy/reference.rb
35
+ - lib/jimmy/declaration.rb
36
+ - lib/jimmy/declaration/assertion.rb
37
+ - lib/jimmy/declaration/casting.rb
38
+ - lib/jimmy/declaration/composites.rb
39
+ - lib/jimmy/declaration/number.rb
40
+ - lib/jimmy/declaration/object.rb
41
+ - lib/jimmy/declaration/string.rb
42
+ - lib/jimmy/declaration/types.rb
43
+ - lib/jimmy/error.rb
44
+ - lib/jimmy/file_map.rb
45
+ - lib/jimmy/index.rb
46
+ - lib/jimmy/json/array.rb
47
+ - lib/jimmy/json/collection.rb
48
+ - lib/jimmy/json/hash.rb
49
+ - lib/jimmy/json/pointer.rb
50
+ - lib/jimmy/json/uri.rb
51
+ - lib/jimmy/loaders/base.rb
52
+ - lib/jimmy/loaders/json.rb
53
+ - lib/jimmy/loaders/ruby.rb
54
+ - lib/jimmy/macros.rb
104
55
  - lib/jimmy/schema.rb
105
- - lib/jimmy/schema_creation.rb
106
- - lib/jimmy/schema_type.rb
107
- - lib/jimmy/schema_types.rb
108
- - lib/jimmy/schema_types/array.rb
109
- - lib/jimmy/schema_types/boolean.rb
110
- - lib/jimmy/schema_types/integer.rb
111
- - lib/jimmy/schema_types/null.rb
112
- - lib/jimmy/schema_types/number.rb
113
- - lib/jimmy/schema_types/object.rb
114
- - lib/jimmy/schema_types/string.rb
115
- - lib/jimmy/symbol_array.rb
116
- - lib/jimmy/transform_keys.rb
117
- - lib/jimmy/type_reference.rb
118
- - lib/jimmy/validation_error.rb
56
+ - lib/jimmy/schema/array.rb
57
+ - lib/jimmy/schema/casting.rb
58
+ - lib/jimmy/schema/json.rb
59
+ - lib/jimmy/schema/number.rb
60
+ - lib/jimmy/schema/object.rb
61
+ - lib/jimmy/schema/operators.rb
62
+ - lib/jimmy/schema/string.rb
63
+ - lib/jimmy/schema_with_uri.rb
64
+ - lib/jimmy/schemer_factory.rb
119
65
  - lib/jimmy/version.rb
66
+ - schema07.json
120
67
  homepage: https://github.com/hx/jimmy
121
68
  licenses:
122
69
  - Apache License, Version 2.0
123
- metadata: {}
70
+ metadata:
71
+ homepage_uri: https://github.com/hx/jimmy
72
+ source_code_uri: https://github.com/hx/jimmy
73
+ changelog_uri: https://github.com/hx/jimmy
124
74
  post_install_message:
125
75
  rdoc_options: []
126
76
  require_paths:
@@ -129,16 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
79
  requirements:
130
80
  - - ">="
131
81
  - !ruby/object:Gem::Version
132
- version: '0'
82
+ version: 2.3.0
133
83
  required_rubygems_version: !ruby/object:Gem::Requirement
134
84
  requirements:
135
85
  - - ">="
136
86
  - !ruby/object:Gem::Version
137
87
  version: '0'
138
88
  requirements: []
139
- rubyforge_project:
140
- rubygems_version: 2.6.8
89
+ rubygems_version: 3.0.6
141
90
  signing_key:
142
91
  specification_version: 4
143
- summary: Jimmy the JSON Schema DSL
92
+ summary: Jimmy the Gem
144
93
  test_files: []
data/circle.yml DELETED
@@ -1,11 +0,0 @@
1
- machine:
2
- ruby:
3
- version: '2.1.5'
4
-
5
- dependencies:
6
- pre:
7
- - gem install bundler -v '~>1.9'
8
-
9
- test:
10
- override:
11
- - bundle exec rake spec
@@ -1,34 +0,0 @@
1
- require_relative 'schema_types'
2
-
3
- module Jimmy
4
- class Combination < Array
5
- include SchemaCreation::Referencing
6
-
7
- attr_reader :condition, :schema
8
-
9
- # @param [Symbol] condition One of :one, :all, or :any
10
- def initialize(condition, schema)
11
- @condition = condition
12
- @schema = schema
13
- end
14
-
15
- def domain
16
- schema.domain
17
- end
18
-
19
- def evaluate(types_proc)
20
- instance_exec &types_proc
21
- end
22
-
23
- def compile
24
- data.merge "#{condition}Of" => map(&:compile)
25
- end
26
-
27
- def data
28
- @data ||= {}
29
- end
30
-
31
- SchemaCreation.apply_to(self) { |schema| push schema }
32
-
33
- end
34
- end
@@ -1,38 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Jimmy
4
- class Definitions
5
- include SchemaCreation::Referencing
6
- extend Forwardable
7
- delegate %i[empty? key? map] => :@values
8
-
9
- attr_reader :schema
10
-
11
- def initialize(schema)
12
- @schema = schema
13
- @values = {}
14
- end
15
-
16
- def evaluate(&block)
17
- instance_exec &block
18
- end
19
-
20
- def domain
21
- schema.domain
22
- end
23
-
24
- def compile
25
- map { |k, v| [k.to_s, v.compile] }.to_h
26
- end
27
-
28
- def data
29
- schema.data
30
- end
31
-
32
- def [](key)
33
- @values[key] || (schema.parent && schema.parent.definitions[key])
34
- end
35
-
36
- SchemaCreation.apply_to(self) { |schema, name| @values[name] = schema }
37
- end
38
- end
@@ -1,111 +0,0 @@
1
- require 'uri'
2
- require 'pathname'
3
- require 'json'
4
- require 'json-schema'
5
-
6
- require_relative 'schema_creation'
7
-
8
- module Jimmy
9
- class Domain
10
- DEFAULT_OPTIONS = {
11
- transform_keys: nil
12
- }
13
-
14
- attr_reader :root, :types, :partials, :options, :schemas
15
-
16
- def initialize(root, **options)
17
- @root = URI(root)
18
- @schemas = {}
19
- @types = {}
20
- @partials = {}
21
- @import_paths = []
22
- @uri_formatter = -> _, name { @root + "#{name}.json#" }
23
- @options = DEFAULT_OPTIONS.merge(options)
24
- end
25
-
26
- def domain
27
- self
28
- end
29
-
30
- def import(path)
31
- path = Pathname(path) unless path.is_a? Pathname
32
- @import_paths << path unless @import_paths.include? path
33
-
34
- glob path, only: 'types' do |name, schema|
35
- @types[name.to_sym] = schema
36
- end
37
-
38
- glob path, only: 'partials' do |name|
39
- partial_path = path + 'partials' + "#{name}.rb"
40
- @partials[name] = [partial_path.read, partial_path.to_s]
41
- end
42
-
43
- glob path, ignore: %r`^(types|partials)/` do |name, schema|
44
- @schemas[name] = schema
45
- end
46
- end
47
-
48
- def autoload_type(name)
49
- # TODO: protect from circular dependency
50
- return if types.key? name
51
- @import_paths.each do |import_path|
52
- path = import_path + "types/#{name}.rb"
53
- if path.file?
54
- @types[name] = load_schema_from_path(path, name)
55
- return true
56
- end
57
- end
58
- false
59
- end
60
-
61
- def [](schema_name)
62
- @schemas[schema_name.to_s]
63
- end
64
-
65
- def export(path = nil, &serializer)
66
- path = Pathname(path) if path.is_a? String
67
- raise 'Please specify an export directory' unless path.is_a?(Pathname) && (path.directory? || !path.exist?)
68
- path.mkpath
69
- @schemas.each { |name, schema| export_schema schema, path + "#{name.to_s}.json", &serializer }
70
- @types.each { |name, schema| export_schema schema, path + 'types' + "#{name.to_s}.json", &serializer }
71
- end
72
-
73
- def uri_for(name)
74
- @uri_formatter.call root, name
75
- end
76
-
77
- def uri_format(&block)
78
- @uri_formatter = block
79
- end
80
-
81
- private
82
-
83
- def glob(base_path, only: '.', ignore: nil, &block)
84
- lookup_path = base_path + only
85
- Dir[lookup_path + '**/*.rb'].each do |full_path|
86
- full_path = Pathname(full_path)
87
- relative_path = full_path.relative_path_from(lookup_path)
88
- next if ignore === relative_path.to_s
89
- args = [relative_path.to_s[0..-4]]
90
- args << load_schema_from_path(full_path, full_path.relative_path_from(base_path).to_s[0..-4]) if block.arity == 2
91
- yield *args
92
- end
93
- end
94
-
95
- def load_schema_from_path(path, name)
96
- @schema_name = name
97
- instance_eval(path.read, path.to_s).schema.tap do |schema|
98
- schema.name = name.to_s
99
- JSON::Validator.add_schema JSON::Schema.new(schema.to_h, nil)
100
- end
101
- end
102
-
103
- def export_schema(schema, target_path)
104
- target_path.parent.mkpath
105
- target_path.write block_given? ? yield(schema.to_h) : JSON.pretty_generate(schema.to_h)
106
- end
107
-
108
- SchemaCreation.apply_to self
109
-
110
- end
111
- end
@@ -1,93 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Jimmy
4
- class Link < Hash
5
- attr_reader :schema
6
-
7
- def initialize(schema, rel, href)
8
- @schema = schema
9
- merge! 'rel' => rel.to_s,
10
- 'href' => href.to_s
11
- end
12
-
13
- def dsl
14
- @dsl ||= DSL.new(self)
15
- end
16
-
17
- def schemas
18
- @schemas ||= {}
19
- end
20
-
21
- def domain
22
- schema.domain
23
- end
24
-
25
- def compile
26
- merge schemas.map { |k, v| [(k ? "#{k}Schema" : 'schema'), v.compile] }.to_h
27
- end
28
-
29
- def schema_creator
30
- @schema_creator ||= SchemaCreator.new(self)
31
- end
32
-
33
- class SchemaCreator < Hash
34
- include SchemaCreation::Referencing
35
- extend Forwardable
36
- delegate [:schema, :domain] => :@link
37
-
38
- def initialize(link)
39
- @link = link
40
- end
41
-
42
- def parent
43
- schema
44
- end
45
-
46
- SchemaCreation.apply_to(self) { |schema, prefix| @link.schemas[prefix] = schema }
47
- end
48
-
49
- class DSL
50
- attr_reader :link
51
-
52
- def initialize(link)
53
- @link = link
54
- end
55
-
56
- def domain
57
- link.domain
58
- end
59
-
60
- def title(value)
61
- link['title'] = value
62
- end
63
-
64
- def method(value)
65
- link['method'] = value.to_s.upcase
66
- end
67
-
68
- def evaluate(&block)
69
- instance_exec &block
70
- end
71
-
72
- def schema(*args, prefix: nil, **opts, &block)
73
- if args.empty? && opts.any?
74
- args = opts.shift
75
- type = args.shift
76
- else
77
- type = args.shift || :object
78
- end
79
- args.unshift type, prefix
80
- args << opts if opts.any?
81
- link.schema_creator.__send__ *args, &block
82
- end
83
-
84
- def target_schema(*args, **opts, &block)
85
- schema *args, **opts.merge(prefix: :target), &block
86
- end
87
-
88
- def set(**values)
89
- values.each { |k, v| link[k.to_s] = v }
90
- end
91
- end
92
- end
93
- end