jimmy 0.5.3 → 2.0.2

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 +98 -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 +107 -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
@@ -1,17 +0,0 @@
1
- module Jimmy
2
- class SymbolArray < Array
3
-
4
- def initialize(*args)
5
- super args.flatten.map(&:to_s)
6
- end
7
-
8
- %i(<< push unshift).each do |method|
9
- define_method(method) { |*args| super *args.map(&:to_s) }
10
- end
11
-
12
- %i(+ - | &).each do |method|
13
- define_method(method) { |*args| SymbolArray.new(super args.flatten.map(&:to_s)) }
14
- end
15
-
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- module Jimmy
2
- module TransformKeys
3
- def camel_upper(str)
4
- camel_lower(str).sub(/\A(.)/) { $1.upcase }
5
- end
6
-
7
- def camel_lower(str)
8
- str.gsub(/[-_\s]+(.)/) { $1.upcase }
9
- end
10
-
11
- class Transformer
12
- include TransformKeys
13
-
14
- def cache(method)
15
- (@cache ||= {})[method] ||= {}
16
- end
17
-
18
- def transform(sym, method)
19
- if method
20
- cache(method)[sym] ||= __send__(method, sym.to_s).to_sym
21
- else
22
- sym
23
- end
24
- end
25
-
26
- def transform_ref(str, method)
27
- if method
28
- str.sub(/#(.+)/) { '#' << $1.split('/').map { |part| __send__ method, part }.join('/') }
29
- else
30
- str
31
- end
32
- end
33
- end
34
-
35
- def self.transformer
36
- @transformer ||= Transformer.new
37
- end
38
- end
39
- end
@@ -1,14 +0,0 @@
1
- module Jimmy
2
- class TypeReference < Reference
3
- attr_reader :type
4
-
5
- def initialize(type, domain, *args)
6
- @type = type
7
- uri = domain.root + "types/#{type}.json#"
8
- path = uri.path.dup
9
- path << '?' << uri.query if uri.query
10
- path << '#' << uri.fragment if uri.fragment
11
- super path, domain, *args
12
- end
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Jimmy
4
- class ValidationError < StandardError
5
-
6
- attr_reader :schema, :data, :errors
7
-
8
- def initialize(schema, data, errors)
9
- @schema = schema
10
- @data = data
11
- @errors = errors.map do |info|
12
- OpenStruct.new(
13
- property: info[:fragment][2..-1],
14
- message: info[:message].gsub(/ in schema \S+$/, ''),
15
- aspect: info[:failed_attribute]
16
- )
17
- end
18
- end
19
- end
20
- end