granite-form 0.6.1 → 1.0.0
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/form/model/associations/embeds_many.rb +2 -2
- data/lib/granite/form/model/associations/embeds_one.rb +1 -1
- data/lib/granite/form/model/associations/nested_attributes.rb +2 -1
- data/lib/granite/form/model/associations/references_many.rb +3 -3
- data/lib/granite/form/model/associations/reflections/embeds_many.rb +1 -1
- data/lib/granite/form/model/associations/reflections/embeds_one.rb +1 -1
- data/lib/granite/form/model/associations/reflections/references_many.rb +1 -1
- data/lib/granite/form/model/associations/reflections/references_one.rb +1 -1
- data/lib/granite/form/model/associations/validations.rb +2 -2
- data/lib/granite/form/model/attributes/base.rb +1 -1
- data/lib/granite/form/model/attributes.rb +1 -1
- data/lib/granite/form/model/primary.rb +4 -2
- data/lib/granite/form/model/representation.rb +10 -22
- data/lib/granite/form/model/scopes.rb +9 -34
- data/lib/granite/form/model/validations/associated.rb +1 -1
- data/lib/granite/form/model/validations/nested.rb +4 -15
- data/lib/granite/form/version.rb +1 -1
- metadata +28 -194
- data/.codeclimate.yml +0 -13
- data/.github/workflows/ruby.yml +0 -51
- data/.gitignore +0 -21
- data/.rspec +0 -2
- data/.rubocop.yml +0 -42
- data/.rubocop_todo.yml +0 -325
- data/Appraisals +0 -7
- data/CHANGELOG.md +0 -51
- data/Gemfile +0 -8
- data/Guardfile +0 -77
- data/LICENSE +0 -22
- data/README.md +0 -422
- data/Rakefile +0 -10
- data/docker-compose.yml +0 -14
- data/gemfiles/rails.6.0.gemfile +0 -14
- data/gemfiles/rails.6.1.gemfile +0 -14
- data/gemfiles/rails.7.0.gemfile +0 -14
- data/gemfiles/rails.7.1.gemfile +0 -14
- data/granite-form.gemspec +0 -33
- data/spec/granite/form/active_record/associations_spec.rb +0 -231
- data/spec/granite/form/active_record/nested_attributes_spec.rb +0 -14
- data/spec/granite/form/config_spec.rb +0 -82
- data/spec/granite/form/extensions_spec.rb +0 -12
- data/spec/granite/form/model/associations/embeds_many_spec.rb +0 -478
- data/spec/granite/form/model/associations/embeds_one_spec.rb +0 -371
- data/spec/granite/form/model/associations/nested_attributes_spec.rb +0 -23
- data/spec/granite/form/model/associations/persistence_adapters/active_record_spec.rb +0 -63
- data/spec/granite/form/model/associations/references_many_spec.rb +0 -292
- data/spec/granite/form/model/associations/references_one_spec.rb +0 -184
- data/spec/granite/form/model/associations/reflections/embeds_any_spec.rb +0 -41
- data/spec/granite/form/model/associations/reflections/embeds_many_spec.rb +0 -172
- data/spec/granite/form/model/associations/reflections/embeds_one_spec.rb +0 -120
- data/spec/granite/form/model/associations/reflections/references_many_spec.rb +0 -355
- data/spec/granite/form/model/associations/reflections/references_one_spec.rb +0 -289
- data/spec/granite/form/model/associations/validations_spec.rb +0 -145
- data/spec/granite/form/model/associations_spec.rb +0 -196
- data/spec/granite/form/model/attributes/attribute_spec.rb +0 -137
- data/spec/granite/form/model/attributes/base_spec.rb +0 -130
- data/spec/granite/form/model/attributes/reflections/attribute_spec.rb +0 -52
- data/spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb +0 -27
- data/spec/granite/form/model/attributes/reflections/base_spec.rb +0 -63
- data/spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb +0 -24
- data/spec/granite/form/model/attributes/reflections/collection_spec.rb +0 -37
- data/spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb +0 -24
- data/spec/granite/form/model/attributes/reflections/dictionary_spec.rb +0 -37
- data/spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb +0 -131
- data/spec/granite/form/model/attributes/reflections/represents_spec.rb +0 -93
- data/spec/granite/form/model/attributes/represents_spec.rb +0 -108
- data/spec/granite/form/model/attributes_spec.rb +0 -472
- data/spec/granite/form/model/conventions_spec.rb +0 -11
- data/spec/granite/form/model/dirty_spec.rb +0 -81
- data/spec/granite/form/model/persistence_spec.rb +0 -54
- data/spec/granite/form/model/primary_spec.rb +0 -99
- data/spec/granite/form/model/representation_spec.rb +0 -158
- data/spec/granite/form/model/scopes_spec.rb +0 -91
- data/spec/granite/form/model/validations/associated_spec.rb +0 -114
- data/spec/granite/form/model/validations/nested_spec.rb +0 -222
- data/spec/granite/form/model/validations_spec.rb +0 -58
- data/spec/granite/form/model_spec.rb +0 -11
- data/spec/granite/form/types/active_support/time_zone_spec.rb +0 -24
- data/spec/granite/form/types/array_spec.rb +0 -13
- data/spec/granite/form/types/big_decimal_spec.rb +0 -19
- data/spec/granite/form/types/boolean_spec.rb +0 -21
- data/spec/granite/form/types/collection_spec.rb +0 -23
- data/spec/granite/form/types/date_spec.rb +0 -18
- data/spec/granite/form/types/date_time_spec.rb +0 -18
- data/spec/granite/form/types/dictionary_spec.rb +0 -33
- data/spec/granite/form/types/float_spec.rb +0 -19
- data/spec/granite/form/types/has_subtype_spec.rb +0 -25
- data/spec/granite/form/types/hash_with_action_controller_parameters_spec.rb +0 -22
- data/spec/granite/form/types/integer_spec.rb +0 -18
- data/spec/granite/form/types/object_spec.rb +0 -88
- data/spec/granite/form/types/string_spec.rb +0 -13
- data/spec/granite/form/types/time_spec.rb +0 -29
- data/spec/granite/form/types/uuid_spec.rb +0 -21
- data/spec/granite/form/util_spec.rb +0 -111
- data/spec/granite/form_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -34
- data/spec/support/active_record.rb +0 -36
- data/spec/support/model_helpers.rb +0 -10
- data/spec/support/muffle_helper.rb +0 -7
- data/spec/support/shared/nested_attribute_examples.rb +0 -370
- data/spec/support/shared/type_examples.rb +0 -7
- data/spec/support/translations.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dda468a489d35aab4f5804326e5f6085402fb2ff75f9fd04ac6cc543d5ef1891
|
|
4
|
+
data.tar.gz: 0b94a79de0efc3b3658e9c947eb7429ba09d9e07e3ce8febbdbc004100c2a7b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d42d8e453b397943f350d360b3fb17d07176631ba30619d46b2cc9acd5d4f81bf79339ff67538d28d67148b74c5ce50afe25a80d3eb38f3cbd69109f055e9de
|
|
7
|
+
data.tar.gz: a54b55d887aaddee4813206c7a4b11f6856fe5d1a6ad703deb2ea1d65ade6f109515c8d686c634c42719f5e32277c7de966439c7017b4e1e20a7c3d23ff1808b
|
|
@@ -22,7 +22,7 @@ module Granite
|
|
|
22
22
|
unless evar_loaded?
|
|
23
23
|
default = Array.wrap(reflection.default(owner))
|
|
24
24
|
if default.present?
|
|
25
|
-
collection = if default.all?
|
|
25
|
+
collection = if default.all?(reflection.klass)
|
|
26
26
|
default
|
|
27
27
|
else
|
|
28
28
|
default.map do |attributes|
|
|
@@ -46,7 +46,7 @@ module Granite
|
|
|
46
46
|
write_source(target.map { |model| model_data(model) })
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def clear
|
|
49
|
+
def clear # rubocop:disable Naming/PredicateMethod
|
|
50
50
|
target
|
|
51
51
|
@target = []
|
|
52
52
|
true
|
|
@@ -29,7 +29,7 @@ module Granite
|
|
|
29
29
|
|
|
30
30
|
super(attrs.merge!(nested_attrs))
|
|
31
31
|
else
|
|
32
|
-
super
|
|
32
|
+
super
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -232,6 +232,7 @@ module Granite
|
|
|
232
232
|
@nested_attributes_methods_module ||= begin
|
|
233
233
|
mod = const_set(:NestedAttributesMethods, Module.new)
|
|
234
234
|
include(mod)
|
|
235
|
+
|
|
235
236
|
mod
|
|
236
237
|
end
|
|
237
238
|
end
|
|
@@ -20,9 +20,9 @@ module Granite
|
|
|
20
20
|
|
|
21
21
|
return [] unless default
|
|
22
22
|
|
|
23
|
-
if default.all?
|
|
23
|
+
if default.all?(reflection.persistence_adapter.data_type)
|
|
24
24
|
default
|
|
25
|
-
elsif default.all?
|
|
25
|
+
elsif default.all?(Hash)
|
|
26
26
|
default.map { |attributes| build_object(attributes) }
|
|
27
27
|
else
|
|
28
28
|
reflection.persistence_adapter.find_all(owner, default)
|
|
@@ -49,7 +49,7 @@ module Granite
|
|
|
49
49
|
reader
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
def clear
|
|
52
|
+
def clear # rubocop:disable Naming/PredicateMethod
|
|
53
53
|
attribute.pollute do
|
|
54
54
|
write_source([])
|
|
55
55
|
end
|
|
@@ -4,7 +4,7 @@ module Granite
|
|
|
4
4
|
module Associations
|
|
5
5
|
module Reflections
|
|
6
6
|
class EmbedsMany < EmbedsAny
|
|
7
|
-
def self.build(target, generated_methods, name, options = {}, &
|
|
7
|
+
def self.build(target, generated_methods, name, options = {}, &_block)
|
|
8
8
|
if target < Granite::Form::Model::Attributes
|
|
9
9
|
target.add_attribute(Granite::Form::Model::Attributes::Reflections::Base, name,
|
|
10
10
|
type: Object)
|
|
@@ -6,7 +6,7 @@ module Granite
|
|
|
6
6
|
class EmbedsOne < EmbedsAny
|
|
7
7
|
include Singular
|
|
8
8
|
|
|
9
|
-
def self.build(target, generated_methods, name, options = {}, &
|
|
9
|
+
def self.build(target, generated_methods, name, options = {}, &_block)
|
|
10
10
|
if target < Granite::Form::Model::Attributes
|
|
11
11
|
target.add_attribute(Granite::Form::Model::Attributes::Reflections::Base, name,
|
|
12
12
|
type: Object)
|
|
@@ -7,7 +7,7 @@ module Granite
|
|
|
7
7
|
module Associations
|
|
8
8
|
module Reflections
|
|
9
9
|
class ReferencesMany < ReferencesAny
|
|
10
|
-
def self.build(target, generated_methods, name, *args, &
|
|
10
|
+
def self.build(target, generated_methods, name, *args, &_block)
|
|
11
11
|
reflection = super
|
|
12
12
|
|
|
13
13
|
target.add_attribute(
|
|
@@ -25,9 +25,9 @@ module Granite
|
|
|
25
25
|
association_names.each do |name|
|
|
26
26
|
association = association(name)
|
|
27
27
|
invalid_block = if association.reflection.klass.method_defined?(:invalid_ansestry?)
|
|
28
|
-
|
|
28
|
+
lambda(&:invalid_ansestry?)
|
|
29
29
|
else
|
|
30
|
-
|
|
30
|
+
lambda(&:invalid?)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
Granite::Form::Model::Validations::NestedValidator
|
|
@@ -63,7 +63,7 @@ module Granite
|
|
|
63
63
|
_attributes[_attribute_aliases[name] || name]
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
def has_attribute?(name) # rubocop:disable Naming/
|
|
66
|
+
def has_attribute?(name) # rubocop:disable Naming/PredicatePrefix
|
|
67
67
|
name = name.to_s
|
|
68
68
|
_attributes.key?(_attribute_aliases[name] || name)
|
|
69
69
|
end
|
|
@@ -3,6 +3,7 @@ module Granite
|
|
|
3
3
|
module Model
|
|
4
4
|
module Primary
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
|
+
|
|
6
7
|
DEFAULT_PRIMARY_ATTRIBUTE_OPTIONS = lambda do
|
|
7
8
|
{
|
|
8
9
|
type: Granite::Form::UUID,
|
|
@@ -15,6 +16,7 @@ module Granite
|
|
|
15
16
|
delegate :has_primary_attribute?, to: 'self.class'
|
|
16
17
|
|
|
17
18
|
prepend PrependMethods
|
|
19
|
+
|
|
18
20
|
alias_method :eql?, :==
|
|
19
21
|
end
|
|
20
22
|
|
|
@@ -31,7 +33,7 @@ module Granite
|
|
|
31
33
|
|
|
32
34
|
alias primary_attribute primary
|
|
33
35
|
|
|
34
|
-
def has_primary_attribute? # rubocop:disable Naming/
|
|
36
|
+
def has_primary_attribute? # rubocop:disable Naming/PredicatePrefix
|
|
35
37
|
has_attribute? _primary_name
|
|
36
38
|
end
|
|
37
39
|
|
|
@@ -49,7 +51,7 @@ module Granite
|
|
|
49
51
|
object_id == other.object_id
|
|
50
52
|
end
|
|
51
53
|
else
|
|
52
|
-
super
|
|
54
|
+
super
|
|
53
55
|
end
|
|
54
56
|
end
|
|
55
57
|
end
|
|
@@ -25,7 +25,7 @@ module Granite
|
|
|
25
25
|
|
|
26
26
|
super(attrs.merge!(represented_attrs))
|
|
27
27
|
else
|
|
28
|
-
super
|
|
28
|
+
super
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -41,9 +41,7 @@ module Granite
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def represented_attributes
|
|
44
|
-
@represented_attributes ||= _attributes.values.
|
|
45
|
-
attribute.is_a? Granite::Form::Model::Attributes::Reflections::Represents
|
|
46
|
-
end
|
|
44
|
+
@represented_attributes ||= _attributes.values.grep(Granite::Form::Model::Attributes::Reflections::Represents)
|
|
47
45
|
end
|
|
48
46
|
|
|
49
47
|
def represented_names_and_aliases
|
|
@@ -55,7 +53,7 @@ module Granite
|
|
|
55
53
|
|
|
56
54
|
private
|
|
57
55
|
|
|
58
|
-
def run_validations! # :
|
|
56
|
+
def run_validations! # rubocop:disable Naming/PredicateMethod
|
|
59
57
|
super
|
|
60
58
|
emerge_represented_attributes_errors!
|
|
61
59
|
errors.empty?
|
|
@@ -75,26 +73,16 @@ module Granite
|
|
|
75
73
|
end
|
|
76
74
|
end
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
options = options.merge(message: error.message.html_safe)
|
|
84
|
-
|
|
85
|
-
errors.add(to, error.type, **options)
|
|
86
|
-
end
|
|
76
|
+
def move_errors(from, to)
|
|
77
|
+
errors.where(from).each do |error|
|
|
78
|
+
options = error.options
|
|
79
|
+
# If we generate message for built-in validation, we don't want to later escape it in our monkey-patch
|
|
80
|
+
options = options.merge(message: error.message.html_safe)
|
|
87
81
|
|
|
88
|
-
errors.
|
|
82
|
+
errors.add(to, error.type, **options)
|
|
89
83
|
end
|
|
90
|
-
else
|
|
91
|
-
# up to 6.0.x
|
|
92
|
-
def move_errors(from, to)
|
|
93
|
-
return unless errors.messages.key?(from) && errors.messages[from].present?
|
|
94
84
|
|
|
95
|
-
|
|
96
|
-
errors.delete(from)
|
|
97
|
-
end
|
|
85
|
+
errors.delete(from)
|
|
98
86
|
end
|
|
99
87
|
end
|
|
100
88
|
end
|
|
@@ -41,43 +41,18 @@ module Granite
|
|
|
41
41
|
super || self.class._scope_model.respond_to?(method)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
else
|
|
53
|
-
super
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
|
58
|
-
def method_missing(method, *args, **kwargs, &block)
|
|
59
|
-
with_scope do
|
|
60
|
-
model = self.class._scope_model
|
|
61
|
-
if model.respond_to?(method)
|
|
62
|
-
model.public_send(method, *args, **kwargs, &block)
|
|
63
|
-
else
|
|
64
|
-
super
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
else
|
|
69
|
-
# up to 2.6.x
|
|
70
|
-
def method_missing(method, *args, &block)
|
|
71
|
-
with_scope do
|
|
72
|
-
model = self.class._scope_model
|
|
73
|
-
if model.respond_to?(method)
|
|
74
|
-
model.public_send(method, *args, &block)
|
|
75
|
-
else
|
|
76
|
-
super
|
|
77
|
-
end
|
|
44
|
+
def method_missing(method, ...)
|
|
45
|
+
with_scope do
|
|
46
|
+
model = self.class._scope_model
|
|
47
|
+
if model.respond_to?(method)
|
|
48
|
+
result = model.public_send(method, ...)
|
|
49
|
+
result.is_a?(Granite::Form::Model::Scopes) ? result : model.scope_class.new(result)
|
|
50
|
+
else
|
|
51
|
+
super
|
|
78
52
|
end
|
|
79
53
|
end
|
|
80
54
|
end
|
|
55
|
+
|
|
81
56
|
def with_scope
|
|
82
57
|
previous_scope = self.class._scope_model.current_scope
|
|
83
58
|
self.class._scope_model.current_scope = self
|
|
@@ -7,7 +7,7 @@ module Granite
|
|
|
7
7
|
invalid_records = Array.wrap(value).reject do |r|
|
|
8
8
|
r.respond_to?(:valid?) && r.valid?(record.validation_context)
|
|
9
9
|
end
|
|
10
|
-
record.errors.add(attribute, :invalid, **options
|
|
10
|
+
record.errors.add(attribute, :invalid, **options, value: value) if invalid_records.present?
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -15,21 +15,10 @@ module Granite
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
to.import(error, attribute: key) unless to.messages_for(key).include?(error.message)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
else
|
|
26
|
-
# up to 6.0.x
|
|
27
|
-
def self.import_errors(from, to, prefix)
|
|
28
|
-
from.each do |key, message|
|
|
29
|
-
key = "#{prefix}.#{key}"
|
|
30
|
-
to[key] << message
|
|
31
|
-
to[key].uniq!
|
|
32
|
-
end
|
|
18
|
+
def self.import_errors(from, to, prefix)
|
|
19
|
+
from.each do |error|
|
|
20
|
+
key = "#{prefix}.#{error.attribute}"
|
|
21
|
+
to.import(error, attribute: key) unless to.messages_for(key).include?(error.message)
|
|
33
22
|
end
|
|
34
23
|
end
|
|
35
24
|
|
data/lib/granite/form/version.rb
CHANGED