quickery 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/quickery/active_record_extensions/dsl.rb +10 -1
- data/lib/quickery/association_chain.rb +1 -1
- data/lib/quickery/quickery_builder.rb +1 -15
- data/lib/quickery/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ee53003d29d3dfa2bf9cd981c5d6f154bb49a8a07538d846acff0b30adb52d
|
4
|
+
data.tar.gz: 2bf0d7a7e35f9d46ec2fabeacd11f36479f4165c1110b8e75d3336e91329d5f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290d4b4ba0ee7b2f239619231c07ceb848a79d3b858b0b03287644459a67ed5ae826e426b6b291debee23afecaca4221434df1c21fda53bb8d662791f8afda0e
|
7
|
+
data.tar.gz: 1c3b3f6b7817550bf272e342b88c70964ff8955f9bc73fe81e6c234f0036c19d4ed8278cf6b0ec45346d8dee010842060b51d3e17c8593a753ffb6943dc1fc35
|
data/README.md
CHANGED
@@ -185,7 +185,7 @@ end
|
|
185
185
|
```
|
186
186
|
|
187
187
|
## Gotchas
|
188
|
-
* Quickery makes use of Rails model callbacks such as `
|
188
|
+
* Quickery makes use of Rails model callbacks such as `before_update`. This meant that data-integrity holds unless `update_columns` or `update_column` is used which bypasses model callbacks, or unless any manual SQL update is performed.
|
189
189
|
* Quickery does not automatically update old records existing in the database that were created before you integrate Quickery, or before you add new/more Quickery-attributes for that model. One solution is [`recreate_quickery_cache!`](#recreate_quickery_cache) below.
|
190
190
|
|
191
191
|
## DSL
|
@@ -203,7 +203,6 @@ end
|
|
203
203
|
* `{ branch: { name: :branch_name, id: :branch_id }` will create two `Quickery::QuickeryBuilder`
|
204
204
|
* In this particular example, you are required to specify `belongs_to :branch` in this model
|
205
205
|
* Similarly, you are required to specify `belongs_to :company` inside `Branch` model, `belongs_to :country` inside `Company` model; etc...
|
206
|
-
* defines a set of "hidden" Quickery `before_save`, `before_update`, `before_destroy`, and `before_create` callbacks across all models specified in the quickery-defined attribute association chain.
|
207
206
|
* quickery-defined attributes such as say `:branch_company_country_category_name` are updated by Quickery automatically whenever any of it's dependent records across models have been changed. Note that updates in this way do not trigger model callbacks, as I wanted to isolate logic and scope of Quickery by not triggering model callbacks that you already have.
|
208
207
|
* quickery-defined attributes such as say `:branch_company_country_category_name` are READ-only! Do not update these attributes manually. You can, but it will not automatically update the other end, and thus will break data integrity. If you want to re-update these attributes to match the other end, see `recreate_quickery_cache!` below.
|
209
208
|
|
@@ -235,6 +234,16 @@ end
|
|
235
234
|
# => 'Ireland'
|
236
235
|
```
|
237
236
|
|
237
|
+
##### `determine_quickery_values`
|
238
|
+
* returns a Hash of all quickery-defined attributes mapped to the current "actual" supposed values
|
239
|
+
* i.e. you can do something like the following:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
employee = Employee.first
|
243
|
+
puts employee.determine_quickery_values
|
244
|
+
# => { branch_company_country_id: 1, branch_compnay_country_name: 'Ireland' }
|
245
|
+
```
|
246
|
+
|
238
247
|
## TODOs
|
239
248
|
* Possibly support two-way mapping of attributes? So that you can do, say... `employee.update!(branch_company_name: 'somenewcompanyname')`
|
240
249
|
* Support `has_many` as currently only `belongs_to` is supported. This would then allow us to cache Array of values.
|
@@ -264,6 +273,9 @@ See [my detailed comparisons](other_similar_gems_comparison.md)
|
|
264
273
|
5. Create new Pull Request
|
265
274
|
|
266
275
|
## Changelog
|
276
|
+
* 1.1.0
|
277
|
+
* added helper method [`determine_quickery_values`](#determine_quickery_values)
|
278
|
+
* fixed `recreate_quickery_cache!` raising `NilClass` error when the immediate association is nil
|
267
279
|
* 1.0.0
|
268
280
|
* Done (TODO): DSL changed from quickery (block) into quickery (hash). Thanks to @xire28 and @sshaw_ in my [reddit post](https://www.reddit.com/r/ruby/comments/9dlcc5/i_just_published_a_new_gem_quickery_an/) for the suggestion.
|
269
281
|
* Done (TODO): Now updates in one go, instead of updating record per quickery-attribute, thereby greatly improving speed.
|
@@ -12,6 +12,7 @@ module Quickery
|
|
12
12
|
attr_accessor :quickery_association_chain_dependers
|
13
13
|
attr_accessor :quickery_association_chain_dependees
|
14
14
|
attr_accessor :quickery_association_chain_intermediaries
|
15
|
+
attr_accessor :quickery_builders
|
15
16
|
|
16
17
|
def quickery(mappings)
|
17
18
|
mappings_builder = MappingsBuilder.new(model: self, mappings: mappings.with_indifferent_access)
|
@@ -33,7 +34,15 @@ module Quickery
|
|
33
34
|
raise ArgumentError, "No defined quickery builder for #{depender_column_name}. Defined values are #{self.class.quickery_builders.keys}" unless quickery_builder
|
34
35
|
|
35
36
|
dependee_record = quickery_builder.association_chains.first.dependee_record(self)
|
36
|
-
dependee_record.
|
37
|
+
dependee_record.public_send(quickery_builder.dependee_column_name) if dependee_record
|
38
|
+
end
|
39
|
+
|
40
|
+
def determine_quickery_values
|
41
|
+
quickery_values = {}
|
42
|
+
self.class.quickery_builders.each do |depender_column_name, quickery_builder|
|
43
|
+
quickery_values[depender_column_name] = determine_quickery_value(depender_column_name)
|
44
|
+
end
|
45
|
+
quickery_values
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
@@ -79,7 +79,7 @@ module Quickery
|
|
79
79
|
|
80
80
|
child_association_chains(include_self: true).inject(from_record) do |from_record, association_chain|
|
81
81
|
if association_chain.belongs_to
|
82
|
-
from_record.send(association_chain.belongs_to.name)
|
82
|
+
from_record.send(association_chain.belongs_to.name) if from_record
|
83
83
|
else
|
84
84
|
from_record
|
85
85
|
end
|
@@ -13,8 +13,7 @@ module Quickery
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def add_to_model
|
16
|
-
|
17
|
-
# include this to the list of quickery builders defined for this model
|
16
|
+
@model.quickery_builders ||= {}
|
18
17
|
@model.quickery_builders[depender_column_name] = self
|
19
18
|
end
|
20
19
|
|
@@ -28,18 +27,5 @@ module Quickery
|
|
28
27
|
@callbacks_builder = CallbacksBuilder.new(quickery_builder: self)
|
29
28
|
@callbacks_builder.build_callbacks
|
30
29
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def define_quickery_builders_in_model_class
|
35
|
-
# set default empty Hash if first time setting quickery_builders
|
36
|
-
@model.class_eval do
|
37
|
-
@quickery_builders = {}
|
38
|
-
|
39
|
-
class << self
|
40
|
-
attr_reader :quickery_builders
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
30
|
end
|
45
31
|
end
|
data/lib/quickery/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman Polidario
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|