granite 0.14.0 → 0.14.2
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 +4 -4
- data/lib/granite/action/subject.rb +10 -5
- data/lib/granite/action.rb +1 -1
- data/lib/granite/context_proxy/proxy.rb +0 -2
- data/lib/granite/represents/attribute.rb +5 -0
- data/lib/granite/version.rb +1 -1
- data/lib/granite.rb +1 -1
- metadata +22 -9
- data/lib/granite/ruby3_compatibility.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d4056c068ce20c44a4951e8f2c6c52be5d37913900c79a32041627c08bc09d9
|
4
|
+
data.tar.gz: 00127702e26bd46b17778e6ead007acce5b59cfbfd1a3b01d315c8286b6b6d36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611de3a2edf7e5b7e42d2da1b06f35cef0a49c3ff7712c3bffe57a4f0deecd7e3454216dd13617914d211825a34764b223ad8b780537a9d4d0122c7aa0e0e429
|
7
|
+
data.tar.gz: 5273870b5a1a2c0d93deef1a21d3c8f3d40bda27e19588199a6301544d7d454df50243dbd4bedf766988ddf37502e177c727f998d5fabbbfeef4761bd395d31d
|
@@ -29,15 +29,20 @@ module Granite
|
|
29
29
|
|
30
30
|
self._subject = name
|
31
31
|
end
|
32
|
+
|
33
|
+
def subject?
|
34
|
+
_subject.present?
|
35
|
+
end
|
36
|
+
|
37
|
+
def subject_reflection
|
38
|
+
reflect_on_association(_subject)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
def initialize(*args)
|
35
|
-
|
36
|
-
super
|
37
|
-
return
|
38
|
-
end
|
43
|
+
return super unless self.class.subject? # rubocop:disable Lint/ReturnInVoidContext
|
39
44
|
|
40
|
-
reflection = self.class.
|
45
|
+
reflection = self.class.subject_reflection
|
41
46
|
attributes = extract_initialize_attributes(args)
|
42
47
|
|
43
48
|
subject_attributes = extract_subject_attributes!(attributes, reflection)
|
data/lib/granite/action.rb
CHANGED
@@ -72,7 +72,7 @@ module Granite
|
|
72
72
|
else
|
73
73
|
def merge_errors(other_errors)
|
74
74
|
other_errors.each do |error|
|
75
|
-
errors.import(error) unless errors.
|
75
|
+
errors.import(error) unless errors.messages[error.attribute].include?(error.message)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Granite
|
2
2
|
module Represents
|
3
3
|
class Attribute < ActiveData::Model::Attributes::Attribute
|
4
|
+
types = {}
|
5
|
+
types[ActiveRecord::Enum::EnumType] = String if defined?(ActiveRecord)
|
6
|
+
TYPES = types.freeze
|
7
|
+
|
4
8
|
delegate :writer, :reader, :reader_before_type_cast, to: :reflection
|
5
9
|
|
6
10
|
def initialize(*_args)
|
@@ -84,6 +88,7 @@ module Granite
|
|
84
88
|
|
85
89
|
attribute_type = reference.type_for_attribute(name.to_s)
|
86
90
|
|
91
|
+
return TYPES[attribute_type.class] if TYPES.key?(attribute_type.class)
|
87
92
|
return Granite::Action::Types::Collection.new(convert_type_to_value_class(attribute_type.subtype)) if attribute_type.respond_to?(:subtype)
|
88
93
|
|
89
94
|
convert_type_to_value_class(attribute_type)
|
data/lib/granite/version.rb
CHANGED
data/lib/granite.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'active_support/dependencies'
|
2
2
|
require 'action_controller'
|
3
|
+
require 'ruby2_keywords'
|
3
4
|
|
4
5
|
require 'granite/version'
|
5
6
|
require 'granite/config'
|
6
7
|
require 'granite/context'
|
7
8
|
require 'granite/util'
|
8
|
-
require 'granite/ruby3_compatibility'
|
9
9
|
|
10
10
|
module Granite
|
11
11
|
def self.config
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toptal Engineering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0.16'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby2_keywords
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.0.5
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.0.5
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: activerecord
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -302,8 +316,8 @@ dependencies:
|
|
302
316
|
- - "~>"
|
303
317
|
- !ruby/object:Gem::Version
|
304
318
|
version: '0.15'
|
305
|
-
description:
|
306
|
-
email:
|
319
|
+
description:
|
320
|
+
email:
|
307
321
|
executables: []
|
308
322
|
extensions: []
|
309
323
|
extra_rdoc_files: []
|
@@ -375,7 +389,6 @@ files:
|
|
375
389
|
- lib/granite/rspec/projector_helpers.rb
|
376
390
|
- lib/granite/rspec/raise_validation_error.rb
|
377
391
|
- lib/granite/rspec/satisfy_preconditions.rb
|
378
|
-
- lib/granite/ruby3_compatibility.rb
|
379
392
|
- lib/granite/translations.rb
|
380
393
|
- lib/granite/typecasters.rb
|
381
394
|
- lib/granite/util.rb
|
@@ -387,7 +400,7 @@ homepage: https://github.com/toptal/granite
|
|
387
400
|
licenses:
|
388
401
|
- MIT
|
389
402
|
metadata: {}
|
390
|
-
post_install_message:
|
403
|
+
post_install_message:
|
391
404
|
rdoc_options: []
|
392
405
|
require_paths:
|
393
406
|
- lib
|
@@ -402,8 +415,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
402
415
|
- !ruby/object:Gem::Version
|
403
416
|
version: '0'
|
404
417
|
requirements: []
|
405
|
-
rubygems_version: 3.
|
406
|
-
signing_key:
|
418
|
+
rubygems_version: 3.2.33
|
419
|
+
signing_key:
|
407
420
|
specification_version: 4
|
408
421
|
summary: Another business actions architecture for Rails apps
|
409
422
|
test_files: []
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Granite
|
2
|
-
module Ruby3Compatibility
|
3
|
-
# Method definition aimed to provide compatibility between Ruby 2.6 and 3.0
|
4
|
-
# It's being recommended in this article
|
5
|
-
# https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
#
|
9
|
-
# ruby2_keywords def a_method(argument, *args, &block)
|
10
|
-
# delegating_to_method(argument, *args, &block)
|
11
|
-
# end
|
12
|
-
def ruby2_keywords(*)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|