granite 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/granite_generator.rb +5 -5
- data/lib/generators/templates/granite_action.rb.erb +1 -1
- data/lib/generators/templates/granite_action_spec.rb.erb +1 -1
- data/lib/generators/templates/granite_business_action.rb.erb +1 -1
- data/lib/granite/action/performing.rb +0 -1
- data/lib/granite/action/types/collection.rb +11 -3
- data/lib/granite/base.rb +0 -1
- data/lib/granite/represents/attribute.rb +31 -35
- data/lib/granite/version.rb +1 -1
- data/lib/granite.rb +1 -2
- metadata +19 -6
- data/lib/granite/typecasters.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0a4953c8a4a24dfab614a8831bb8b39cda81d4a0b2d7e3ea8f2bb5d3d8eccc4
|
4
|
+
data.tar.gz: 6f1655c4167aef595d7c36fcd0fbde9e72376bd1fec2dafc38e6dc508f4f0417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0b0f97527283426bdaf8f5d25cf033053f0636958578621c84f5c8fc0c01f70528f1d759213ac0cddbc3327d5b06951b231d18cce3e987c612697dabb90c89
|
7
|
+
data.tar.gz: deff30290527973e4dee79d4584c7ffd5090a80737da57d1efe48e8fcdd89d0e11d220c8b5c81b55f313f2d3ced81b097ab454c67065b6db458629e18924c236
|
@@ -5,11 +5,11 @@ class GraniteGenerator < Rails::Generators::NamedBase
|
|
5
5
|
class_option :collection, type: :boolean, aliases: '-C', desc: 'Generate collection action'
|
6
6
|
|
7
7
|
def create_action
|
8
|
-
template 'granite_action.rb.erb', "apq/actions
|
9
|
-
template 'granite_business_action.rb.erb', "apq/actions
|
8
|
+
template 'granite_action.rb.erb', "apq/actions/#{file_path}.rb"
|
9
|
+
template 'granite_business_action.rb.erb', "apq/actions/#{class_path.join('/')}/business_action.rb" unless options.collection?
|
10
10
|
template 'granite_base_action.rb.erb', 'apq/actions/base_action.rb', skip: true
|
11
|
-
template 'granite_action_spec.rb.erb', "spec/apq/actions
|
12
|
-
empty_directory "apq/actions
|
11
|
+
template 'granite_action_spec.rb.erb', "spec/apq/actions/#{file_path}_spec.rb"
|
12
|
+
empty_directory "apq/actions/#{file_path}/#{projector}" if projector
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -18,7 +18,7 @@ class GraniteGenerator < Rails::Generators::NamedBase
|
|
18
18
|
if options.collection?
|
19
19
|
'BaseAction'
|
20
20
|
else
|
21
|
-
"
|
21
|
+
"#{class_path.join('/').camelize}::BusinessAction"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -2,10 +2,18 @@ module Granite
|
|
2
2
|
class Action
|
3
3
|
module Types
|
4
4
|
class Collection
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :subtype_definition
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(subtype_definition)
|
8
|
+
@subtype_definition = subtype_definition
|
9
|
+
end
|
10
|
+
|
11
|
+
def ensure_type(value)
|
12
|
+
if value.respond_to? :transform_values
|
13
|
+
value.transform_values { |v| subtype_definition.ensure_type(v) }
|
14
|
+
elsif value.respond_to?(:map)
|
15
|
+
value.map { |v| subtype_definition.ensure_type(v) }
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
data/lib/granite/base.rb
CHANGED
@@ -4,6 +4,11 @@ module Granite
|
|
4
4
|
types = {}
|
5
5
|
types[ActiveRecord::Enum::EnumType] = String if defined?(ActiveRecord)
|
6
6
|
TYPES = types.freeze
|
7
|
+
GRANITE_COLLECTION_TYPES = [
|
8
|
+
Granite::Form::Model::Attributes::ReferenceMany,
|
9
|
+
Granite::Form::Model::Attributes::Collection,
|
10
|
+
Granite::Form::Model::Attributes::Dictionary
|
11
|
+
].freeze
|
7
12
|
delegate :writer, :reader, :reader_before_type_cast, to: :reflection
|
8
13
|
|
9
14
|
def initialize(*_args)
|
@@ -17,23 +22,12 @@ module Granite
|
|
17
22
|
reference.public_send(writer, read) if reference.respond_to?(writer)
|
18
23
|
end
|
19
24
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def type
|
27
|
-
return reflection.options[:type] if reflection.options[:type].present?
|
28
|
-
|
29
|
-
granite_form_type || type_from_type_for_attribute || super
|
30
|
-
end
|
31
|
-
|
32
|
-
def typecaster
|
33
|
-
@typecaster ||= begin
|
34
|
-
type_class = type.instance_of?(Class) ? type : type.class
|
35
|
-
@typecaster = Granite::Form.typecaster(type_class.ancestors.grep(Class))
|
36
|
-
end
|
25
|
+
def type_definition
|
26
|
+
@type_definition ||= if reflection.options[:type].present?
|
27
|
+
build_type_definition(reflection.options[:type])
|
28
|
+
else
|
29
|
+
granite_form_type_definition || active_record_type_definition || super
|
30
|
+
end
|
37
31
|
end
|
38
32
|
|
39
33
|
def changed?
|
@@ -54,7 +48,7 @@ module Granite
|
|
54
48
|
return unless reference.respond_to?(reader)
|
55
49
|
|
56
50
|
variable_cache(:value) do
|
57
|
-
normalize(enumerize(
|
51
|
+
normalize(enumerize(type_definition.ensure_type(defaultize(reference.public_send(reader)))))
|
58
52
|
end
|
59
53
|
end
|
60
54
|
|
@@ -66,31 +60,33 @@ module Granite
|
|
66
60
|
end
|
67
61
|
end
|
68
62
|
|
69
|
-
def
|
63
|
+
def granite_form_type_definition
|
70
64
|
return nil unless reference.is_a?(Granite::Form::Model)
|
71
65
|
|
72
66
|
reference_attribute = reference.attribute(name)
|
73
67
|
|
74
68
|
return nil if reference_attribute.nil?
|
75
69
|
|
76
|
-
|
77
|
-
|
78
|
-
Granite::
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
reference_attribute.type # TODO: create `type_for_attribute` method inside of Granite::Form
|
70
|
+
type_definition = build_type_definition(reference_attribute.type)
|
71
|
+
if GRANITE_COLLECTION_TYPES.any? { |klass| reference_attribute.is_a? klass }
|
72
|
+
Granite::Action::Types::Collection.new(type_definition)
|
73
|
+
else
|
74
|
+
type_definition
|
75
|
+
end
|
83
76
|
end
|
84
77
|
|
85
|
-
def
|
78
|
+
def active_record_type_definition
|
86
79
|
return nil unless reference.respond_to?(:type_for_attribute)
|
87
80
|
|
88
81
|
attribute_type = reference.type_for_attribute(attribute_name.to_s)
|
89
82
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
83
|
+
if TYPES.key?(attribute_type.class)
|
84
|
+
build_type_definition(TYPES[attribute_type.class])
|
85
|
+
elsif attribute_type.respond_to?(:subtype)
|
86
|
+
Granite::Action::Types::Collection.new(convert_active_model_type_to_definition(attribute_type.subtype))
|
87
|
+
else
|
88
|
+
convert_active_model_type_to_definition(attribute_type)
|
89
|
+
end
|
94
90
|
end
|
95
91
|
|
96
92
|
def attribute_name
|
@@ -99,10 +95,10 @@ module Granite
|
|
99
95
|
reference.class.attribute_aliases[name.to_s] || name
|
100
96
|
end
|
101
97
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
def convert_active_model_type_to_definition(attribute_type)
|
99
|
+
type = attribute_type.try(:value_class) ||
|
100
|
+
Form::Model::Associations::PersistenceAdapters::ActiveRecord::TYPES[attribute_type.type&.to_sym]
|
101
|
+
build_type_definition(type) if type
|
106
102
|
end
|
107
103
|
end
|
108
104
|
end
|
data/lib/granite/version.rb
CHANGED
data/lib/granite.rb
CHANGED
@@ -25,7 +25,6 @@ require 'granite/dispatcher'
|
|
25
25
|
require 'granite/action'
|
26
26
|
require 'granite/projector'
|
27
27
|
require 'granite/routing'
|
28
|
-
require 'granite/
|
29
|
-
require 'granite/rails' if defined?(::Rails)
|
28
|
+
require 'granite/rails' if defined?(Rails)
|
30
29
|
|
31
30
|
Granite::Form.base_concern = Granite::Base
|
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.15.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toptal Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 0.3.0
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 0.3.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +120,20 @@ dependencies:
|
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: bump
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: capybara
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -390,7 +404,6 @@ files:
|
|
390
404
|
- lib/granite/rspec/raise_validation_error.rb
|
391
405
|
- lib/granite/rspec/satisfy_preconditions.rb
|
392
406
|
- lib/granite/translations.rb
|
393
|
-
- lib/granite/typecasters.rb
|
394
407
|
- lib/granite/util.rb
|
395
408
|
- lib/granite/version.rb
|
396
409
|
- lib/rubocop-granite.rb
|
@@ -415,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
415
428
|
- !ruby/object:Gem::Version
|
416
429
|
version: '0'
|
417
430
|
requirements: []
|
418
|
-
rubygems_version: 3.
|
431
|
+
rubygems_version: 3.3.26
|
419
432
|
signing_key:
|
420
433
|
specification_version: 4
|
421
434
|
summary: Another business actions architecture for Rails apps
|
data/lib/granite/typecasters.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'granite/form'
|
2
|
-
|
3
|
-
Granite::Form.typecaster('Granite::Action::Types::Collection') do |value, attribute|
|
4
|
-
typecaster = Granite::Form.typecaster(attribute.type.subtype)
|
5
|
-
if value.respond_to? :transform_values
|
6
|
-
value.transform_values { |v| typecaster.call(v, attribute) }
|
7
|
-
elsif value.respond_to?(:map)
|
8
|
-
value.map { |v| typecaster.call(v, attribute) }
|
9
|
-
end
|
10
|
-
end
|