surrealist 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +1 -1
- data/.rubocop.yml +1 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +2 -1
- data/benchmarks/surrealist_vs_ams.rb +3 -1
- data/bin/console +1 -0
- data/gemfiles/activerecord42.gemfile +1 -1
- data/lib/surrealist/exception_raiser.rb +3 -3
- data/lib/surrealist/helper.rb +3 -1
- data/lib/surrealist/schema_definer.rb +1 -1
- data/lib/surrealist/string_utils.rb +9 -9
- data/lib/surrealist/type_helper.rb +1 -1
- data/lib/surrealist/vars_helper.rb +8 -6
- data/lib/surrealist/version.rb +1 -1
- data/lib/surrealist/wrapper.rb +3 -1
- data/surrealist.gemspec +5 -5
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b3b9607bd4d83e7848c7ff0a3e247147f8af67f15a4b017b19d3c0c9742147
|
4
|
+
data.tar.gz: dac6c3c5040e5df0c452808a96d9edb96f8ec47f366d70f5308ea85aeecb06f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbae1762a9545c3aab9831cb9acfbef3a8ae754d0fdc73dc4c64c3bdeb4f92edf9f4fc861ec6156c330a54a0dd7fe6b2747fca9c97bf6f07a89a3c0f7bd1c795
|
7
|
+
data.tar.gz: 63ce4bceaa20ba5a4d770cacfd0f4fc574206ee58c22524ea63147ea11a4ced49bc19197895fc0ccfdee24706b410951c789243e3201e037de4fecbe212d46f7
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.3
|
3
3
|
Exclude:
|
4
4
|
- './gemfiles/*gemfile'
|
5
5
|
- './tmp/*'
|
@@ -169,6 +169,3 @@ Style/MethodMissingSuper:
|
|
169
169
|
Style/EvalWithLocation:
|
170
170
|
Exclude:
|
171
171
|
- spec/**/*.rb
|
172
|
-
|
173
|
-
Style/AccessModifierDeclarations:
|
174
|
-
Enabled: false
|
data/.travis.yml
CHANGED
@@ -7,12 +7,12 @@ matrix:
|
|
7
7
|
include:
|
8
8
|
- rvm: ruby-head
|
9
9
|
gemfile: Gemfile
|
10
|
+
- rvm: 2.6
|
11
|
+
gemfile: Gemfile
|
10
12
|
- rvm: 2.5
|
11
13
|
gemfile: Gemfile
|
12
14
|
- rvm: 2.4
|
13
15
|
gemfile: Gemfile
|
14
16
|
- rvm: 2.3
|
15
|
-
gemfile: Gemfile
|
16
|
-
- rvm: 2.2
|
17
17
|
gemfile: gemfiles/activerecord42.gemfile
|
18
18
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 1.3.3
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
* Struct serialization ([@wildkain][]) [#135](https://github.com/nesaulov/surrealist/pull/135)
|
5
|
+
|
1
6
|
# 1.3.2
|
2
7
|
|
3
8
|
## Fixed
|
@@ -127,3 +132,4 @@
|
|
127
132
|
[@stefkin]: https://github.com/stefkin
|
128
133
|
[@gjhenrique]: https://github.com/gjhenrique
|
129
134
|
[@kolasss]: https://github.com/kolasss
|
135
|
+
[@wildkain]: https://github.com/wildkain
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![Inline docs](http://inch-ci.org/github/nesaulov/surrealist.svg?branch=master)](http://inch-ci.org/github/nesaulov/surrealist)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/surrealist.svg)](https://rubygems.org/gems/surrealist)
|
6
6
|
[![Open Source Helpers](https://www.codetriage.com/nesaulov/surrealist/badges/users.svg)](https://www.codetriage.com/nesaulov/surrealist)
|
7
|
+
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
|
7
8
|
|
8
9
|
![Surrealist](surrealist-icon.png)
|
9
10
|
|
@@ -780,7 +781,7 @@ Car.new.surrealize
|
|
780
781
|
### Other notes
|
781
782
|
* nil values are allowed by default, so if you have, say, `age: String`, but the actual value is nil,
|
782
783
|
type check will be passed. If you want to be strict about `nil`s consider using `Dry::Types`.
|
783
|
-
* Surrealist [officially supports](https://travis-ci.org/nesaulov/surrealist) MRI Ruby 2.
|
784
|
+
* Surrealist [officially supports](https://travis-ci.org/nesaulov/surrealist) MRI Ruby 2.3+ but should be working on other platforms as well.
|
784
785
|
|
785
786
|
## Roadmap
|
786
787
|
Here is a list of features that are not implemented yet (contributions are welcome):
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
2
4
|
require_relative '../lib/surrealist'
|
3
5
|
require 'benchmark/ips'
|
@@ -7,7 +9,7 @@ require 'active_model_serializers'
|
|
7
9
|
require 'blueprinter'
|
8
10
|
|
9
11
|
ActiveRecord::Base.establish_connection(
|
10
|
-
adapter:
|
12
|
+
adapter: 'sqlite3',
|
11
13
|
database: ':memory:',
|
12
14
|
)
|
13
15
|
|
data/bin/console
CHANGED
@@ -30,9 +30,9 @@ module Surrealist
|
|
30
30
|
|
31
31
|
# A class that raises all Surrealist exceptions
|
32
32
|
module ExceptionRaiser
|
33
|
-
CLASS_NAME_NOT_PASSED = "Can't wrap schema in root key - class name was not passed"
|
34
|
-
MUST_BEHAVE_LIKE_ENUMERABLE = "Can't serialize collection - must behave like enumerable"
|
35
|
-
CLASS_DOESNT_INCLUDE_SURREALIST = 'Class does not include Surrealist'
|
33
|
+
CLASS_NAME_NOT_PASSED = "Can't wrap schema in root key - class name was not passed"
|
34
|
+
MUST_BEHAVE_LIKE_ENUMERABLE = "Can't serialize collection - must behave like enumerable"
|
35
|
+
CLASS_DOESNT_INCLUDE_SURREALIST = 'Class does not include Surrealist'
|
36
36
|
|
37
37
|
class << self
|
38
38
|
# Raises Surrealist::InvalidSchemaDelegation if destination of delegation does not
|
data/lib/surrealist/helper.rb
CHANGED
@@ -16,7 +16,9 @@ module Surrealist
|
|
16
16
|
# 4.2 AR relation object did not include Enumerable (it defined
|
17
17
|
# all necessary method through ActiveRecord::Delegation module),
|
18
18
|
# so we need to explicitly check for this
|
19
|
-
|
19
|
+
return false if object.is_a?(Struct)
|
20
|
+
|
21
|
+
object.is_a?(Enumerable) && !object.instance_of?(Hash) || ar_relation?(object)
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.ar_relation?(object)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Surrealist
|
4
4
|
# A class that defines a method on the object that stores the schema.
|
5
5
|
module SchemaDefiner
|
6
|
-
SCHEMA_TYPE_ERROR = 'Schema should be defined as a hash'
|
6
|
+
SCHEMA_TYPE_ERROR = 'Schema should be defined as a hash'
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# Defines an instance variable on the object that stores the schema.
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module Surrealist
|
4
4
|
# A helper class for strings transformations.
|
5
5
|
module StringUtils
|
6
|
-
DASH = '-'
|
7
|
-
UNDERSCORE = '_'
|
8
|
-
EMPTY_STRING = ''
|
9
|
-
DASH_REGEXP1 = /([A-Z]+)([A-Z][a-z])/o
|
10
|
-
DASH_REGEXP2 = /([a-z\d])([A-Z])/o
|
11
|
-
UNDERSCORE_REGEXP = /(?:^|_)([^_\s]+)/o
|
12
|
-
NAMESPACES_SEPARATOR = '::'
|
13
|
-
UNDERSCORE_SUBSTITUTE = '\1_\2'
|
6
|
+
DASH = '-'
|
7
|
+
UNDERSCORE = '_'
|
8
|
+
EMPTY_STRING = ''
|
9
|
+
DASH_REGEXP1 = /([A-Z]+)([A-Z][a-z])/o.freeze
|
10
|
+
DASH_REGEXP2 = /([a-z\d])([A-Z])/o.freeze
|
11
|
+
UNDERSCORE_REGEXP = /(?:^|_)([^_\s]+)/o.freeze
|
12
|
+
NAMESPACES_SEPARATOR = '::'
|
13
|
+
UNDERSCORE_SUBSTITUTE = '\1_\2'
|
14
14
|
|
15
15
|
class << self
|
16
16
|
# Converts a string to snake_case.
|
@@ -69,7 +69,7 @@ module Surrealist
|
|
69
69
|
#
|
70
70
|
# @return [Hash] a nested hash.
|
71
71
|
def break_namespaces(klass, camelize, nesting_level)
|
72
|
-
Surrealist::ExceptionRaiser.raise_invalid_nesting!(nesting_level) unless nesting_level
|
72
|
+
Surrealist::ExceptionRaiser.raise_invalid_nesting!(nesting_level) unless nesting_level.positive?
|
73
73
|
|
74
74
|
klass.split(NAMESPACES_SEPARATOR).last(nesting_level).reverse.inject({}) do |a, n|
|
75
75
|
camelize ? Hash[camelize(uncapitalize(n), false).to_sym => a] : Hash[underscore(n).to_sym => a]
|
@@ -4,7 +4,7 @@ module Surrealist
|
|
4
4
|
# Service class for type checking
|
5
5
|
module TypeHelper
|
6
6
|
# Dry-types class matcher
|
7
|
-
DRY_TYPE_CLASS = /Dry::Types
|
7
|
+
DRY_TYPE_CLASS = /Dry::Types/.freeze
|
8
8
|
|
9
9
|
class << self
|
10
10
|
# Checks if value returned from a method is an instance of type class specified
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Surrealist
|
2
4
|
# Module for finding and setting hash into vars
|
3
5
|
module VarsHelper
|
4
6
|
# Instance variable name that is set by SchemaDefiner
|
5
|
-
INSTANCE_VARIABLE = '@__surrealist_schema'
|
7
|
+
INSTANCE_VARIABLE = '@__surrealist_schema'
|
6
8
|
# Instance's parent instance variable name that is set by SchemaDefiner
|
7
|
-
PARENT_VARIABLE = '@__surrealist_schema_parent'
|
9
|
+
PARENT_VARIABLE = '@__surrealist_schema_parent'
|
8
10
|
# Class variable name that is set by SchemaDefiner
|
9
|
-
CLASS_VARIABLE = '@@__surrealist_schema'
|
11
|
+
CLASS_VARIABLE = '@@__surrealist_schema'
|
10
12
|
# Regexp to resolve ROM structure
|
11
|
-
ROM_REGEXP = /ROM::Struct/o
|
13
|
+
ROM_REGEXP = /ROM::Struct/o.freeze
|
12
14
|
# Instance variable that keeps serializer classes
|
13
|
-
SERIALIZER_CLASSES = '@__surrealist_serializers'
|
15
|
+
SERIALIZER_CLASSES = '@__surrealist_serializers'
|
14
16
|
# Tag for default behaviour in multiple serializers
|
15
17
|
DEFAULT_TAG = :default
|
16
18
|
|
@@ -49,7 +51,7 @@ module Surrealist
|
|
49
51
|
def find_serializer(klass, tag: nil)
|
50
52
|
tag ||= DEFAULT_TAG
|
51
53
|
hash = klass.instance_variable_get(SERIALIZER_CLASSES)
|
52
|
-
serializer = hash
|
54
|
+
serializer = hash&.fetch(tag.to_sym, nil)
|
53
55
|
Surrealist::ExceptionRaiser.raise_unknown_tag!(tag) if serializer.nil? && tag != DEFAULT_TAG
|
54
56
|
serializer
|
55
57
|
end
|
data/lib/surrealist/version.rb
CHANGED
data/lib/surrealist/wrapper.rb
CHANGED
data/surrealist.gemspec
CHANGED
@@ -22,13 +22,13 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
|
-
spec.required_ruby_version = '>= 2.
|
25
|
+
spec.required_ruby_version = '>= 2.3.0'
|
26
26
|
|
27
27
|
spec.add_runtime_dependency 'oj', '~> 3.0'
|
28
28
|
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
-
spec.add_development_dependency 'pry', '~> 0.
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
31
31
|
spec.add_development_dependency 'rake', '~> 12.3'
|
32
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.66'
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrealist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Esaulov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.8'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.8'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.66'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.66'
|
97
97
|
description: A gem that provides DSL for serialization of plain old Ruby objects to
|
98
98
|
JSON in a declarative style by defining a `schema`. It also provides a trivial type
|
99
99
|
checking in the runtime before serialization.
|
@@ -151,15 +151,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
requirements:
|
152
152
|
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version: 2.
|
154
|
+
version: 2.3.0
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.7.6
|
161
|
+
rubygems_version: 3.0.3
|
163
162
|
signing_key:
|
164
163
|
specification_version: 4
|
165
164
|
summary: A gem that provides DSL for serialization of plain old Ruby objects to JSON
|