form_obj 0.3.0 → 0.4.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.
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_obj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Koltun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-15 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: tree_struct
14
+ name: typed_array
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.2
19
+ version: 1.0.1
20
20
  type: :runtime
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: 1.0.2
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: appraisal
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: |-
112
126
  Form Object with simple DSL which allows nested Form Objects and arrays of Form Objects. Form
113
127
  Object is compatible with Rails form builders, can update its attributes from a hash and serialize them to a hash.
@@ -121,8 +135,9 @@ extra_rdoc_files: []
121
135
  files:
122
136
  - ".gitignore"
123
137
  - ".rspec"
124
- - ".ruby-version"
125
138
  - ".travis.yml"
139
+ - Appraisals
140
+ - CHANGELOG.md
126
141
  - Gemfile
127
142
  - Gemfile.lock
128
143
  - LICENSE.txt
@@ -130,19 +145,33 @@ files:
130
145
  - Rakefile
131
146
  - bin/console
132
147
  - bin/setup
148
+ - bundle_install.sh
133
149
  - form_obj.gemspec
150
+ - gemfiles/3.2.gemfile
151
+ - gemfiles/4.0.gemfile
152
+ - gemfiles/4.1.gemfile
153
+ - gemfiles/4.2.gemfile
154
+ - gemfiles/5.0.gemfile
155
+ - gemfiles/5.1.gemfile
156
+ - gemfiles/5.2.gemfile
157
+ - install_rubies_and_bundler.sh
134
158
  - lib/form_obj.rb
135
- - lib/form_obj/array.rb
136
- - lib/form_obj/attribute.rb
137
- - lib/form_obj/attributes.rb
138
159
  - lib/form_obj/form.rb
139
- - lib/form_obj/mappable.rb
140
- - lib/form_obj/mappable/array.rb
141
- - lib/form_obj/mappable/attribute.rb
142
- - lib/form_obj/mappable/model_attribute.rb
143
- - lib/form_obj/mappable/model_attribute/item.rb
144
- - lib/form_obj/mappable/model_primary_key.rb
160
+ - lib/form_obj/form/array.rb
161
+ - lib/form_obj/form/attribute.rb
162
+ - lib/form_obj/form/attributes.rb
163
+ - lib/form_obj/model_mapper.rb
164
+ - lib/form_obj/model_mapper/array.rb
165
+ - lib/form_obj/model_mapper/attribute.rb
166
+ - lib/form_obj/model_mapper/model_attribute.rb
167
+ - lib/form_obj/model_mapper/model_attribute/item.rb
168
+ - lib/form_obj/model_mapper/model_primary_key.rb
169
+ - lib/form_obj/struct.rb
170
+ - lib/form_obj/struct/array.rb
171
+ - lib/form_obj/struct/attribute.rb
172
+ - lib/form_obj/struct/attributes.rb
145
173
  - lib/form_obj/version.rb
174
+ - run_spec.sh
146
175
  homepage: https://github.com/akoltun/form_obj
147
176
  licenses:
148
177
  - MIT
@@ -164,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
193
  version: '0'
165
194
  requirements: []
166
195
  rubyforge_project:
167
- rubygems_version: 2.4.5.3
196
+ rubygems_version: 2.6.14
168
197
  signing_key:
169
198
  specification_version: 4
170
199
  summary: Simple but powerful form object compatible with Rails form builders.
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.2.8
@@ -1,36 +0,0 @@
1
- require 'tree_struct'
2
-
3
- module FormObj
4
- class Array < ::TreeStruct::Array
5
- def update_attributes(vals)
6
- ids_exists = []
7
- items_to_add = []
8
-
9
- vals.each do |val|
10
- id = primary_key(val)
11
- item = self.find { |i| i.primary_key == id }
12
- if item
13
- item.update_attributes(val)
14
- ids_exists << id
15
- else
16
- items_to_add << val
17
- end
18
- end
19
-
20
- ids_to_remove = self.map(&:primary_key) - ids_exists
21
- self.delete_if { |item| ids_to_remove.include? item.primary_key }
22
-
23
- items_to_add.each do |item|
24
- self.create.update_attributes(item)
25
- end
26
-
27
- sort! { |a, b| vals.index { |val| primary_key(val) == a.primary_key } <=> vals.index { |val| primary_key(val) == b.primary_key } }
28
- end
29
-
30
- private
31
-
32
- def primary_key(hash)
33
- hash.key?(item_class.primary_key.to_sym) ? hash[item_class.primary_key.to_sym] : hash[item_class.primary_key.to_s]
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- require 'tree_struct'
2
-
3
- module FormObj
4
- class Attribute < ::TreeStruct::Attribute
5
- def initialize(name, array: false, class: nil, default: nil, parent:, primary_key: nil, &block)
6
- super(name, array: array, class: binding.local_variable_get(:class), default: default, parent: parent, &block)
7
-
8
- @nested_class.instance_variable_set(:@model_name, ActiveModel::Name.new(@nested_class, nil, name.to_s)) if !@nested_class && block_given?
9
-
10
- if primary_key
11
- if @nested_class
12
- @nested_class.primary_key = primary_key
13
- else
14
- parent.primary_key = name.to_sym
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,13 +0,0 @@
1
- require 'tree_struct'
2
-
3
- module FormObj
4
- class Attributes < ::TreeStruct::Attributes
5
- def find(name)
6
- @items.find { |item| item.name == name.to_sym }
7
- end
8
-
9
- def each(&block)
10
- @items.each(&block)
11
- end
12
- end
13
- end