jimmy 0.5.3 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.gitignore +4 -3
- data/.rspec +3 -0
- data/.rubocop.yml +61 -0
- data/.ruby-version +1 -1
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/LICENSE +1 -1
- data/README.md +22 -134
- data/Rakefile +91 -1
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/jimmy.gemspec +25 -21
- data/lib/jimmy.rb +23 -15
- data/lib/jimmy/declaration.rb +150 -0
- data/lib/jimmy/declaration/assertion.rb +81 -0
- data/lib/jimmy/declaration/casting.rb +34 -0
- data/lib/jimmy/declaration/composites.rb +41 -0
- data/lib/jimmy/declaration/number.rb +27 -0
- data/lib/jimmy/declaration/object.rb +11 -0
- data/lib/jimmy/declaration/string.rb +98 -0
- data/lib/jimmy/declaration/types.rb +57 -0
- data/lib/jimmy/error.rb +9 -0
- data/lib/jimmy/file_map.rb +166 -0
- data/lib/jimmy/index.rb +78 -0
- data/lib/jimmy/json/array.rb +93 -0
- data/lib/jimmy/json/collection.rb +90 -0
- data/lib/jimmy/json/hash.rb +118 -0
- data/lib/jimmy/json/pointer.rb +119 -0
- data/lib/jimmy/json/uri.rb +144 -0
- data/lib/jimmy/loaders/base.rb +30 -0
- data/lib/jimmy/loaders/json.rb +15 -0
- data/lib/jimmy/loaders/ruby.rb +21 -0
- data/lib/jimmy/macros.rb +37 -0
- data/lib/jimmy/schema.rb +107 -87
- data/lib/jimmy/schema/array.rb +95 -0
- data/lib/jimmy/schema/casting.rb +17 -0
- data/lib/jimmy/schema/json.rb +40 -0
- data/lib/jimmy/schema/number.rb +47 -0
- data/lib/jimmy/schema/object.rb +108 -0
- data/lib/jimmy/schema/operators.rb +96 -0
- data/lib/jimmy/schema/string.rb +44 -0
- data/lib/jimmy/schema_with_uri.rb +53 -0
- data/lib/jimmy/schemer_factory.rb +65 -0
- data/lib/jimmy/version.rb +3 -1
- data/schema07.json +172 -0
- metadata +50 -101
- data/circle.yml +0 -11
- data/lib/jimmy/combination.rb +0 -34
- data/lib/jimmy/definitions.rb +0 -38
- data/lib/jimmy/domain.rb +0 -111
- data/lib/jimmy/link.rb +0 -93
- data/lib/jimmy/reference.rb +0 -39
- data/lib/jimmy/schema_creation.rb +0 -121
- data/lib/jimmy/schema_type.rb +0 -100
- data/lib/jimmy/schema_types.rb +0 -42
- data/lib/jimmy/schema_types/array.rb +0 -30
- data/lib/jimmy/schema_types/boolean.rb +0 -6
- data/lib/jimmy/schema_types/integer.rb +0 -8
- data/lib/jimmy/schema_types/null.rb +0 -6
- data/lib/jimmy/schema_types/number.rb +0 -34
- data/lib/jimmy/schema_types/object.rb +0 -45
- data/lib/jimmy/schema_types/string.rb +0 -40
- data/lib/jimmy/symbol_array.rb +0 -17
- data/lib/jimmy/transform_keys.rb +0 -39
- data/lib/jimmy/type_reference.rb +0 -14
- data/lib/jimmy/validation_error.rb +0 -20
data/lib/jimmy/symbol_array.rb
DELETED
@@ -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
|
data/lib/jimmy/transform_keys.rb
DELETED
@@ -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
|
data/lib/jimmy/type_reference.rb
DELETED
@@ -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
|