granite-form 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/workflows/ruby.yml +3 -5
  4. data/Appraisals +1 -1
  5. data/CHANGELOG.md +16 -0
  6. data/README.md +6 -13
  7. data/gemfiles/{rails.5.0.gemfile → rails.7.1.gemfile} +3 -3
  8. data/granite-form.gemspec +4 -4
  9. data/lib/granite/form/model/associations/nested_attributes.rb +2 -2
  10. data/lib/granite/form/model/associations/reflections/embeds_many.rb +1 -1
  11. data/lib/granite/form/model/associations/reflections/embeds_one.rb +11 -1
  12. data/lib/granite/form/model/associations/reflections/references_one.rb +2 -0
  13. data/lib/granite/form/model/associations/reflections/singular.rb +0 -14
  14. data/lib/granite/form/model/attributes/attribute.rb +3 -21
  15. data/lib/granite/form/model/attributes/base.rb +6 -24
  16. data/lib/granite/form/model/attributes/reference_many.rb +1 -1
  17. data/lib/granite/form/model/attributes/reference_one.rb +1 -1
  18. data/lib/granite/form/model/attributes/reflections/attribute.rb +4 -4
  19. data/lib/granite/form/model/attributes/reflections/base/build_type_definition.rb +38 -0
  20. data/lib/granite/form/model/attributes/reflections/base.rb +12 -10
  21. data/lib/granite/form/model/attributes/reflections/collection/build_type_definition.rb +19 -0
  22. data/lib/granite/form/model/attributes/reflections/dictionary/build_type_definition.rb +19 -0
  23. data/lib/granite/form/model/attributes/reflections/dictionary.rb +0 -3
  24. data/lib/granite/form/model/attributes/reflections/represents/build_type_definition.rb +73 -0
  25. data/lib/granite/form/model/attributes/reflections/represents.rb +10 -2
  26. data/lib/granite/form/model/attributes/represents.rb +22 -37
  27. data/lib/granite/form/model/attributes.rb +10 -2
  28. data/lib/granite/form/model/representation.rb +1 -0
  29. data/lib/granite/form/model/validations.rb +6 -0
  30. data/lib/granite/form/model.rb +1 -1
  31. data/lib/granite/form/types/active_support/time_zone.rb +2 -0
  32. data/lib/granite/form/types/array.rb +2 -0
  33. data/lib/granite/form/types/big_decimal.rb +2 -0
  34. data/lib/granite/form/types/boolean.rb +2 -0
  35. data/lib/granite/form/types/collection.rb +11 -0
  36. data/lib/granite/form/types/date.rb +2 -0
  37. data/lib/granite/form/types/date_time.rb +2 -0
  38. data/lib/granite/form/types/dictionary.rb +23 -0
  39. data/lib/granite/form/types/float.rb +2 -0
  40. data/lib/granite/form/types/has_subtype.rb +18 -0
  41. data/lib/granite/form/types/hash_with_action_controller_parameters.rb +2 -0
  42. data/lib/granite/form/types/integer.rb +2 -0
  43. data/lib/granite/form/types/object.rb +28 -0
  44. data/lib/granite/form/types/string.rb +2 -0
  45. data/lib/granite/form/types/time.rb +2 -0
  46. data/lib/granite/form/types/uuid.rb +2 -0
  47. data/lib/granite/form/types.rb +3 -0
  48. data/lib/granite/form/util.rb +55 -0
  49. data/lib/granite/form/version.rb +1 -1
  50. data/lib/granite/form.rb +1 -0
  51. data/spec/granite/form/model/associations/references_many_spec.rb +1 -1
  52. data/spec/granite/form/model/associations/references_one_spec.rb +4 -4
  53. data/spec/granite/form/model/attributes/attribute_spec.rb +0 -29
  54. data/spec/granite/form/model/attributes/base_spec.rb +18 -0
  55. data/spec/granite/form/model/attributes/reflections/attribute_spec.rb +0 -9
  56. data/spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb +27 -0
  57. data/spec/granite/form/model/attributes/reflections/base_spec.rb +16 -10
  58. data/spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb +24 -0
  59. data/spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb +24 -0
  60. data/spec/granite/form/model/attributes/reflections/dictionary_spec.rb +0 -6
  61. data/spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb +129 -0
  62. data/spec/granite/form/model/attributes/reflections/represents_spec.rb +43 -20
  63. data/spec/granite/form/model/attributes/represents_spec.rb +78 -55
  64. data/spec/granite/form/model/attributes_spec.rb +84 -23
  65. data/spec/granite/form/model/dirty_spec.rb +0 -6
  66. data/spec/granite/form/model/representation_spec.rb +4 -7
  67. data/spec/granite/form/model/validations_spec.rb +28 -1
  68. data/spec/granite/form/types/collection_spec.rb +22 -0
  69. data/spec/granite/form/types/dictionary_spec.rb +32 -0
  70. data/spec/granite/form/types/has_subtype_spec.rb +20 -0
  71. data/spec/granite/form/types/object_spec.rb +50 -4
  72. data/spec/granite/form/util_spec.rb +108 -0
  73. data/spec/support/active_record.rb +3 -0
  74. metadata +40 -31
  75. data/gemfiles/rails.5.1.gemfile +0 -14
  76. data/gemfiles/rails.5.2.gemfile +0 -14
  77. data/lib/granite/form/model/attributes/collection.rb +0 -19
  78. data/lib/granite/form/model/attributes/dictionary.rb +0 -28
  79. data/lib/granite/form/model/attributes/localized.rb +0 -44
  80. data/lib/granite/form/model/attributes/reflections/localized.rb +0 -45
  81. data/lib/granite/form/model/localization.rb +0 -26
  82. data/spec/granite/form/model/attributes/collection_spec.rb +0 -72
  83. data/spec/granite/form/model/attributes/dictionary_spec.rb +0 -100
  84. data/spec/granite/form/model/attributes/localized_spec.rb +0 -103
  85. data/spec/granite/form/model/attributes/reflections/localized_spec.rb +0 -37
@@ -23,15 +23,12 @@ describe Granite::Form::Model::Representation do
23
23
  specify { expect(Post.new(author: author).rate).to eq(42) }
24
24
  specify { expect(Post.new(author: author).rate_before_type_cast).to eq('42') }
25
25
  specify { expect(Post.new(rate: '33', author: author).rate).to eq(33) }
26
- specify { expect(Post.new(rate: '33', author: author).author.rate).to eq(33) }
27
26
  specify { expect(Post.new(r: '33', author: author).rate).to eq(33) }
28
- specify { expect(Post.new(r: '33', author: author).author.rate).to eq(33) }
29
27
  specify { expect(Post.new(author: author).rate?).to eq(true) }
30
28
  specify { expect(Post.new(rate: nil, author: author).rate?).to eq(false) }
31
29
 
32
30
  specify { expect(Post.new.rate).to be_nil }
33
31
  specify { expect(Post.new.rate_before_type_cast).to be_nil }
34
- specify { expect { Post.new(rate: '33') }.to raise_error(NoMethodError) }
35
32
 
36
33
  context 'ActionController::Parameters' do
37
34
  let(:params) { instance_double('ActionController::Parameters', to_unsafe_hash: {rate: '33', author: author}) }
@@ -48,12 +45,13 @@ describe Granite::Form::Model::Representation do
48
45
  expect(Post.new(author: author, rate: '33').changes)
49
46
  .to eq('author' => [nil, author], 'rate' => [42, 33])
50
47
 
48
+ author.rate = 33
51
49
  expect(Post.new(author: author, rate: '33').changes)
52
50
  .to eq('author' => [nil, author])
53
51
  end
54
52
  end
55
53
 
56
- context do
54
+ context 'when represents references_one association' do
57
55
  before do
58
56
  stub_class(:author, ActiveRecord::Base)
59
57
 
@@ -71,7 +69,6 @@ describe Granite::Form::Model::Representation do
71
69
  specify { expect(Post.reflect_on_attribute(:name).reference).to eq('author') }
72
70
 
73
71
  specify { expect(Post.new(name: '33', author: author).name).to eq('33') }
74
- specify { expect(Post.new(name: '33', author: author).author.name).to eq('33') }
75
72
  end
76
73
 
77
74
  context 'multiple attributes in a single represents definition' do
@@ -89,11 +86,11 @@ describe Granite::Form::Model::Representation do
89
86
  end
90
87
  end
91
88
 
92
- let(:author) { Author.new(first_name: 'John', last_name: 'Doe') }
89
+ let(:author) { Author.new }
93
90
  let(:post) { Post.new }
94
91
 
95
92
  specify do
96
- expect { post.update(author: author) }
93
+ expect { post.update(first_name: 'John', last_name: 'Doe') }
97
94
  .to change { post.first_name }.to('John')
98
95
  .and change { post.last_name }.to('Doe')
99
96
  end
@@ -1,10 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Granite::Form::Model::Validations do
4
+ let!(:add_validations) { model.validates :name, presence: true }
5
+
4
6
  let(:model) do
5
7
  stub_model(:model) do
6
8
  attribute :name, String
7
- validates :name, presence: true
9
+ end
10
+ end
11
+
12
+ before { add_validations }
13
+
14
+ describe '.validates_nested?' do
15
+ subject { model.validates_presence?(:name) }
16
+
17
+ it { is_expected.to be_truthy }
18
+
19
+ context 'when using string name' do
20
+ subject { model.validates_presence?('name') }
21
+
22
+ it { is_expected.to be_truthy }
23
+ end
24
+
25
+ context 'when attribute has no validations' do
26
+ let(:add_validations) {}
27
+
28
+ it { is_expected.to be_falsey }
29
+ end
30
+
31
+ context 'when attribute has different validations' do
32
+ let(:add_validations) { model.validates :name, length: {maximum: 100} }
33
+
34
+ it { is_expected.to be_falsey }
8
35
  end
9
36
  end
10
37
 
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Granite::Form::Types::Collection do
4
+ subject(:type) { described_class.new(subtype_definition) }
5
+ let(:element_type) { Dummy }
6
+ let(:subtype_definition) { Granite::Form::Types::Object.new(element_type, reflection, nil) }
7
+ let(:reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:field) }
8
+ let(:dummy_object) { Dummy.new }
9
+
10
+ before { stub_class :dummy }
11
+
12
+ describe '#prepare' do
13
+ specify { expect(subject.prepare([dummy_object, Object.new])).to eq([dummy_object, nil]) }
14
+ specify { expect(subject.prepare(dummy_object)).to eq([dummy_object]) }
15
+
16
+ context 'with Hash collection' do
17
+ let(:element_type) { Hash }
18
+
19
+ specify { expect(subject.prepare([{key: 'value'}])).to eq([{key: 'value'}]) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Granite::Form::Types::Dictionary do
6
+ subject(:type) { described_class.new(subtype_definition) }
7
+ let(:element_type) { Dummy }
8
+ let(:subtype_definition) { Granite::Form::Types::Object.new(element_type, reflection, nil) }
9
+ let(:reflection) { build_reflection }
10
+ let(:dummy) { Dummy.new }
11
+ let(:dummy2) { Dummy.new }
12
+
13
+ def build_reflection(**options)
14
+ Granite::Form::Model::Attributes::Reflections::Dictionary.new(:field, options)
15
+ end
16
+
17
+ before { stub_class :dummy }
18
+
19
+ describe '#prepare' do
20
+ specify { expect(subject.prepare(one: dummy, two: Object.new)).to eq('one' => dummy, 'two' => nil) }
21
+ specify { expect(subject.prepare(three: dummy)).to eq('three' => dummy) }
22
+ specify { expect(subject.prepare([['one', dummy]])).to eq('one' => dummy) }
23
+ specify { expect(subject.prepare(nil)).to eq({}) }
24
+
25
+ context 'when keys are set' do
26
+ let(:reflection) { build_reflection keys: %w[one two] }
27
+
28
+ specify { expect(subject.prepare(three: dummy)).to eq({}) }
29
+ specify { expect(subject.prepare(nil)).to eq({}) }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Granite::Form::Types::HasSubtype do
6
+ subject(:type) { described_class.new(subtype_definition) }
7
+ let(:subtype_definition) { Granite::Form::Types::Object.new(Dummy, reflection, nil) }
8
+ let(:reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:field) }
9
+ let(:dummy_object) { Dummy.new }
10
+
11
+ before { stub_class :dummy }
12
+
13
+ describe '#build_duplicate' do
14
+ subject { type.build_duplicate(new_reflection, new_model) }
15
+ let(:new_model) { double('new_model') }
16
+ let(:new_reflection) { double('new_reflection') }
17
+
18
+ it { is_expected.to have_attributes(subtype_definition: have_attributes(type: Dummy, reflection: new_reflection, owner: new_model)) }
19
+ end
20
+ end
@@ -3,12 +3,32 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Granite::Form::Types::Object do
6
- subject(:type) { described_class.new(String, reflection, model.new) }
7
- let(:model) { stub_model }
8
- let(:reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:field) }
6
+ subject(:type) { build_type(reflection: reflection) }
7
+ let(:model) { Model.new }
8
+ let(:reflection) { build_reflection }
9
+
10
+ before do
11
+ stub_model :model
12
+ end
13
+
14
+ def build_reflection(name: :field, **options)
15
+ Granite::Form::Model::Attributes::Reflections::Base.new(name, options)
16
+ end
17
+
18
+ def build_type(type: String, reflection: nil, **options)
19
+ described_class.new(type, reflection || build_reflection(**options), model)
20
+ end
9
21
 
10
22
  describe '#initialize' do
11
- it { is_expected.to have_attributes(type: String, reflection: reflection, owner: an_instance_of(model)) }
23
+ it { is_expected.to have_attributes(type: String, reflection: reflection, owner: model) }
24
+ end
25
+
26
+ describe '#build_duplicate' do
27
+ subject { type.build_duplicate(new_reflection, new_model) }
28
+ let(:new_model) { double('new_model') }
29
+ let(:new_reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:new_field) }
30
+
31
+ it { is_expected.to have_attributes(type: String, reflection: new_reflection, owner: new_model) }
12
32
  end
13
33
 
14
34
  describe 'typecasting' do
@@ -37,4 +57,30 @@ RSpec.describe Granite::Form::Types::Object do
37
57
  specify { expect(typecast(nil)).to be_nil }
38
58
  end
39
59
  end
60
+
61
+ describe '#enum' do
62
+ before { allow(model).to receive_messages(value: 1..5) }
63
+
64
+ specify { expect(build_type.enum).to eq([].to_set) }
65
+ specify { expect(build_type(enum: []).enum).to eq([].to_set) }
66
+ specify { expect(build_type(enum: 'hello').enum).to eq(['hello'].to_set) }
67
+ specify { expect(build_type(enum: %w[hello world]).enum).to eq(%w[hello world].to_set) }
68
+ specify { expect(build_type(enum: [1..5]).enum).to eq([1..5].to_set) }
69
+ specify { expect(build_type(enum: 1..5).enum).to eq((1..5).to_a.to_set) }
70
+ specify { expect(build_type(enum: -> { 1..5 }).enum).to eq((1..5).to_a.to_set) }
71
+ specify { expect(build_type(enum: -> { 'hello' }).enum).to eq(['hello'].to_set) }
72
+ specify { expect(build_type(enum: -> { ['hello', 42] }).enum).to eq(['hello', 42].to_set) }
73
+ specify { expect(build_type(enum: -> { value }).enum).to eq((1..5).to_a.to_set) }
74
+ end
75
+
76
+ describe '#prepare' do
77
+ specify { expect(build_type.prepare('anything')).to eq('anything') }
78
+ specify { expect(build_type(enum: %w[hello 42]).prepare('hello')).to eq('hello') }
79
+ specify { expect(build_type(enum: %w[hello 42]).prepare('world')).to eq(nil) }
80
+ specify { expect(build_type(enum: %w[hello 42]).prepare('42')).to eq('42') }
81
+ specify { expect(build_type(enum: %w[hello 42]).prepare(42)).to eq(nil) }
82
+ specify { expect(build_type(enum: -> { 'hello' }).prepare('hello')).to eq('hello') }
83
+ specify { expect(build_type(type: Integer, enum: -> { 1..5 }).prepare(2)).to eq(2) }
84
+ specify { expect(build_type(type: Integer, enum: -> { 1..5 }).prepare(42)).to eq(nil) }
85
+ end
40
86
  end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Granite::Form::Util do
4
+ subject(:dummy) { Dummy.new('John') }
5
+
6
+ before do
7
+ stub_class(:dummy, Object) do
8
+ attr_accessor :name
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ end
13
+
14
+ def full_name(last_name)
15
+ [name, last_name].join(' ')
16
+ end
17
+ end
18
+
19
+ Dummy.include described_class
20
+ end
21
+
22
+ describe '#evaluate' do
23
+ subject { dummy.evaluate(target) }
24
+ let(:target) { 'Peter' }
25
+
26
+ it { is_expected.to eq('Peter') }
27
+
28
+ context 'when symbol is passed' do
29
+ let(:target) { :name }
30
+
31
+ it { is_expected.to eq('John') }
32
+ end
33
+
34
+ context 'when lambda is passed' do
35
+ let(:target) { -> { name } }
36
+
37
+ it { is_expected.to eq('John') }
38
+ end
39
+
40
+ context 'with extra arguments' do
41
+ subject { dummy.evaluate(target, 'Doe') }
42
+
43
+ context 'when symbol is passed' do
44
+ let(:target) { :full_name }
45
+
46
+ it { is_expected.to eq('John Doe') }
47
+ end
48
+
49
+ context 'when lambda is passed' do
50
+ let(:target) { ->(last_name) { ['John', last_name].join(' ') } }
51
+
52
+ it { is_expected.to eq('John Doe') }
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#evaluate_if_proc' do
58
+ subject { dummy.evaluate(target) }
59
+ let(:target) { 'Peter' }
60
+
61
+ it { is_expected.to eq('Peter') }
62
+
63
+ context 'when lambda is passed' do
64
+ let(:target) { -> { name } }
65
+
66
+ it { is_expected.to eq('John') }
67
+ end
68
+
69
+ context 'with extra arguments' do
70
+ subject { dummy.evaluate(target, 'Doe') }
71
+
72
+ let(:target) { ->(last_name) { ['John', last_name].join(' ') } }
73
+
74
+ it { is_expected.to eq('John Doe') }
75
+ end
76
+ end
77
+
78
+ describe '#conditions_satisfied?' do
79
+ subject { dummy.conditions_satisfied?(**conditions) }
80
+ let(:conditions) { {if: -> { name == 'John' }} }
81
+
82
+ it { is_expected.to be_truthy }
83
+
84
+ context 'when if condition is satisfied' do
85
+ before { dummy.name = 'Peter' }
86
+
87
+ it { is_expected.to be_falsey }
88
+ end
89
+
90
+ context 'when unless condition is passed' do
91
+ let(:conditions) { {unless: :name} }
92
+
93
+ it { is_expected.to be_falsey }
94
+ end
95
+
96
+ context 'when no condition is passed' do
97
+ let(:conditions) { {} }
98
+
99
+ it { is_expected.to be_truthy }
100
+ end
101
+
102
+ context 'when both if & unless are passed' do
103
+ let(:conditions) { {if: :name, unless: :name} }
104
+
105
+ it { expect { subject }.to raise_error(ArgumentError) }
106
+ end
107
+ end
108
+ end
@@ -16,5 +16,8 @@ ActiveRecord::Schema.define do
16
16
 
17
17
  create_table :authors, force: :cascade do |t|
18
18
  t.column :name, :string
19
+ t.column :status, :integer
20
+ t.column :related_ids, :integer, array: true
21
+ t.column :data, :text
19
22
  end
20
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granite-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
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-12-22 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '6.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: '5.0'
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -170,28 +170,28 @@ dependencies:
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: '5.0'
173
+ version: '6.0'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: '5.0'
180
+ version: '6.0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: activesupport
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: '5.0'
187
+ version: '6.0'
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: '5.0'
194
+ version: '6.0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: tzinfo
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -207,7 +207,7 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  description: Making object from any hash or hash array
210
- email:
210
+ email:
211
211
  executables: []
212
212
  extensions: []
213
213
  extra_rdoc_files: []
@@ -227,12 +227,10 @@ files:
227
227
  - README.md
228
228
  - Rakefile
229
229
  - docker-compose.yml
230
- - gemfiles/rails.5.0.gemfile
231
- - gemfiles/rails.5.1.gemfile
232
- - gemfiles/rails.5.2.gemfile
233
230
  - gemfiles/rails.6.0.gemfile
234
231
  - gemfiles/rails.6.1.gemfile
235
232
  - gemfiles/rails.7.0.gemfile
233
+ - gemfiles/rails.7.1.gemfile
236
234
  - granite-form.gemspec
237
235
  - lib/granite/form.rb
238
236
  - lib/granite/form/active_record/associations.rb
@@ -268,23 +266,22 @@ files:
268
266
  - lib/granite/form/model/attributes.rb
269
267
  - lib/granite/form/model/attributes/attribute.rb
270
268
  - lib/granite/form/model/attributes/base.rb
271
- - lib/granite/form/model/attributes/collection.rb
272
- - lib/granite/form/model/attributes/dictionary.rb
273
- - lib/granite/form/model/attributes/localized.rb
274
269
  - lib/granite/form/model/attributes/reference_many.rb
275
270
  - lib/granite/form/model/attributes/reference_one.rb
276
271
  - lib/granite/form/model/attributes/reflections/attribute.rb
277
272
  - lib/granite/form/model/attributes/reflections/base.rb
273
+ - lib/granite/form/model/attributes/reflections/base/build_type_definition.rb
278
274
  - lib/granite/form/model/attributes/reflections/collection.rb
275
+ - lib/granite/form/model/attributes/reflections/collection/build_type_definition.rb
279
276
  - lib/granite/form/model/attributes/reflections/dictionary.rb
280
- - lib/granite/form/model/attributes/reflections/localized.rb
277
+ - lib/granite/form/model/attributes/reflections/dictionary/build_type_definition.rb
281
278
  - lib/granite/form/model/attributes/reflections/reference_many.rb
282
279
  - lib/granite/form/model/attributes/reflections/reference_one.rb
283
280
  - lib/granite/form/model/attributes/reflections/represents.rb
281
+ - lib/granite/form/model/attributes/reflections/represents/build_type_definition.rb
284
282
  - lib/granite/form/model/attributes/represents.rb
285
283
  - lib/granite/form/model/conventions.rb
286
284
  - lib/granite/form/model/dirty.rb
287
- - lib/granite/form/model/localization.rb
288
285
  - lib/granite/form/model/persistence.rb
289
286
  - lib/granite/form/model/primary.rb
290
287
  - lib/granite/form/model/representation.rb
@@ -298,9 +295,12 @@ files:
298
295
  - lib/granite/form/types/array.rb
299
296
  - lib/granite/form/types/big_decimal.rb
300
297
  - lib/granite/form/types/boolean.rb
298
+ - lib/granite/form/types/collection.rb
301
299
  - lib/granite/form/types/date.rb
302
300
  - lib/granite/form/types/date_time.rb
301
+ - lib/granite/form/types/dictionary.rb
303
302
  - lib/granite/form/types/float.rb
303
+ - lib/granite/form/types/has_subtype.rb
304
304
  - lib/granite/form/types/hash_with_action_controller_parameters.rb
305
305
  - lib/granite/form/types/integer.rb
306
306
  - lib/granite/form/types/object.rb
@@ -308,6 +308,7 @@ files:
308
308
  - lib/granite/form/types/time.rb
309
309
  - lib/granite/form/types/uuid.rb
310
310
  - lib/granite/form/undefined_class.rb
311
+ - lib/granite/form/util.rb
311
312
  - lib/granite/form/version.rb
312
313
  - spec/granite/form/active_record/associations_spec.rb
313
314
  - spec/granite/form/active_record/nested_attributes_spec.rb
@@ -328,14 +329,14 @@ files:
328
329
  - spec/granite/form/model/associations_spec.rb
329
330
  - spec/granite/form/model/attributes/attribute_spec.rb
330
331
  - spec/granite/form/model/attributes/base_spec.rb
331
- - spec/granite/form/model/attributes/collection_spec.rb
332
- - spec/granite/form/model/attributes/dictionary_spec.rb
333
- - spec/granite/form/model/attributes/localized_spec.rb
334
332
  - spec/granite/form/model/attributes/reflections/attribute_spec.rb
333
+ - spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb
335
334
  - spec/granite/form/model/attributes/reflections/base_spec.rb
335
+ - spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb
336
336
  - spec/granite/form/model/attributes/reflections/collection_spec.rb
337
+ - spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb
337
338
  - spec/granite/form/model/attributes/reflections/dictionary_spec.rb
338
- - spec/granite/form/model/attributes/reflections/localized_spec.rb
339
+ - spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb
339
340
  - spec/granite/form/model/attributes/reflections/represents_spec.rb
340
341
  - spec/granite/form/model/attributes/represents_spec.rb
341
342
  - spec/granite/form/model/attributes_spec.rb
@@ -353,15 +354,19 @@ files:
353
354
  - spec/granite/form/types/array_spec.rb
354
355
  - spec/granite/form/types/big_decimal_spec.rb
355
356
  - spec/granite/form/types/boolean_spec.rb
357
+ - spec/granite/form/types/collection_spec.rb
356
358
  - spec/granite/form/types/date_spec.rb
357
359
  - spec/granite/form/types/date_time_spec.rb
360
+ - spec/granite/form/types/dictionary_spec.rb
358
361
  - spec/granite/form/types/float_spec.rb
362
+ - spec/granite/form/types/has_subtype_spec.rb
359
363
  - spec/granite/form/types/hash_with_action_controller_parameters_spec.rb
360
364
  - spec/granite/form/types/integer_spec.rb
361
365
  - spec/granite/form/types/object_spec.rb
362
366
  - spec/granite/form/types/string_spec.rb
363
367
  - spec/granite/form/types/time_spec.rb
364
368
  - spec/granite/form/types/uuid_spec.rb
369
+ - spec/granite/form/util_spec.rb
365
370
  - spec/granite/form_spec.rb
366
371
  - spec/spec_helper.rb
367
372
  - spec/support/active_record.rb
@@ -373,7 +378,7 @@ files:
373
378
  homepage: https://github.com/toptal/granite-form
374
379
  licenses: []
375
380
  metadata: {}
376
- post_install_message:
381
+ post_install_message:
377
382
  rdoc_options: []
378
383
  require_paths:
379
384
  - lib
@@ -388,8 +393,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
388
393
  - !ruby/object:Gem::Version
389
394
  version: '0'
390
395
  requirements: []
391
- rubygems_version: 3.3.26
392
- signing_key:
396
+ rubygems_version: 3.4.6
397
+ signing_key:
393
398
  specification_version: 4
394
399
  summary: Working with hashes in AR style
395
400
  test_files:
@@ -412,14 +417,14 @@ test_files:
412
417
  - spec/granite/form/model/associations_spec.rb
413
418
  - spec/granite/form/model/attributes/attribute_spec.rb
414
419
  - spec/granite/form/model/attributes/base_spec.rb
415
- - spec/granite/form/model/attributes/collection_spec.rb
416
- - spec/granite/form/model/attributes/dictionary_spec.rb
417
- - spec/granite/form/model/attributes/localized_spec.rb
418
420
  - spec/granite/form/model/attributes/reflections/attribute_spec.rb
421
+ - spec/granite/form/model/attributes/reflections/base/build_type_definition_spec.rb
419
422
  - spec/granite/form/model/attributes/reflections/base_spec.rb
423
+ - spec/granite/form/model/attributes/reflections/collection/build_type_definition_spec.rb
420
424
  - spec/granite/form/model/attributes/reflections/collection_spec.rb
425
+ - spec/granite/form/model/attributes/reflections/dictionary/build_type_definition_spec.rb
421
426
  - spec/granite/form/model/attributes/reflections/dictionary_spec.rb
422
- - spec/granite/form/model/attributes/reflections/localized_spec.rb
427
+ - spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb
423
428
  - spec/granite/form/model/attributes/reflections/represents_spec.rb
424
429
  - spec/granite/form/model/attributes/represents_spec.rb
425
430
  - spec/granite/form/model/attributes_spec.rb
@@ -437,15 +442,19 @@ test_files:
437
442
  - spec/granite/form/types/array_spec.rb
438
443
  - spec/granite/form/types/big_decimal_spec.rb
439
444
  - spec/granite/form/types/boolean_spec.rb
445
+ - spec/granite/form/types/collection_spec.rb
440
446
  - spec/granite/form/types/date_spec.rb
441
447
  - spec/granite/form/types/date_time_spec.rb
448
+ - spec/granite/form/types/dictionary_spec.rb
442
449
  - spec/granite/form/types/float_spec.rb
450
+ - spec/granite/form/types/has_subtype_spec.rb
443
451
  - spec/granite/form/types/hash_with_action_controller_parameters_spec.rb
444
452
  - spec/granite/form/types/integer_spec.rb
445
453
  - spec/granite/form/types/object_spec.rb
446
454
  - spec/granite/form/types/string_spec.rb
447
455
  - spec/granite/form/types/time_spec.rb
448
456
  - spec/granite/form/types/uuid_spec.rb
457
+ - spec/granite/form/util_spec.rb
449
458
  - spec/granite/form_spec.rb
450
459
  - spec/spec_helper.rb
451
460
  - spec/support/active_record.rb
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 5.1.0"
6
- gem "activemodel", "~> 5.1.0"
7
- gem "activerecord", "~> 5.1.0"
8
-
9
- group :test do
10
- gem "guard"
11
- gem "guard-rspec"
12
- end
13
-
14
- gemspec path: "../"
@@ -1,14 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 5.2.0"
6
- gem "activemodel", "~> 5.2.0"
7
- gem "activerecord", "~> 5.2.0"
8
-
9
- group :test do
10
- gem "guard"
11
- gem "guard-rspec"
12
- end
13
-
14
- gemspec path: "../"
@@ -1,19 +0,0 @@
1
- module Granite
2
- module Form
3
- module Model
4
- module Attributes
5
- class Collection < Attribute
6
- def read
7
- @value ||= normalize(read_before_type_cast.map do |value|
8
- enumerize(type_definition.ensure_type(value))
9
- end)
10
- end
11
-
12
- def read_before_type_cast
13
- @value_before_type_cast ||= Array.wrap(@value_cache).map { |value| defaultize(value) }
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end