quickery 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +0 -0
- data/Appraisals +0 -0
- data/Gemfile +0 -0
- data/Guardfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +18 -2
- data/Rakefile +0 -0
- data/config.ru +0 -0
- data/developer_guide.md +0 -0
- data/gemfiles/.bundle/config +0 -0
- data/gemfiles/rails_4.gemfile +0 -0
- data/gemfiles/rails_5.gemfile +0 -0
- data/lib/quickery/active_record_extensions/dsl.rb +0 -0
- data/lib/quickery/association_builder.rb +0 -0
- data/lib/quickery/callbacks_builder.rb +0 -0
- data/lib/quickery/quickery_builder.rb +0 -0
- data/lib/quickery/railtie.rb +17 -0
- data/lib/quickery/version.rb +1 -1
- data/lib/quickery.rb +0 -0
- data/other_similar_gems_comparison.md +128 -0
- data/quickery.gemspec +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a115d4b653df7ef6ed09fac7b8aab0aa6116935cd621a47d702dc7a8ddfa186
|
4
|
+
data.tar.gz: f6022d80f9303086374ea8b0e7f2f6b68c1467479d4fb28b3793614c8234cdd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ae04a8c8f3d4f032cb3edd612b1935ea0a6c7032c7990731bb8d3ef5c7105210a49f28049ddd5caabaa105a630841c1292b93293e3c01ad68d420449b656f99
|
7
|
+
data.tar.gz: 0defe1360596b9c02c7124e3ec35c7dfa3b432511a5983d3b7a9400318a4bc670687c7ae99bd7fe2c2b3696af1a940d3b2617851d7e62879c7ed56ec656de400
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Appraisals
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Guardfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
|
12
12
|
* **Rails 4 or 5**
|
13
13
|
* **(Rails 3 still untested)**
|
14
|
+
* `ActiveRecord`
|
14
15
|
|
15
16
|
## Setup
|
16
17
|
1. Add the following to your `Gemfile`:
|
@@ -208,8 +209,12 @@ puts Employee.joins(branch: :company).where(companies: { id: company.id })
|
|
208
209
|
* Possibly support two-way mapping of attributes? So that you can do, say... `employee.update!(branch_company_name: 'somenewcompanyname')`
|
209
210
|
* Improve "updates" across the quickery-defined model callbacks, by grouping attributes that will be updated and update in one go, instead of independently updating per each quickery-defined attribute
|
210
211
|
|
211
|
-
##
|
212
|
-
|
212
|
+
## Other Similar Gems
|
213
|
+
See [my detailed comparisons](other_similar_gems_comparison.md)
|
214
|
+
|
215
|
+
* [persistize](https://github.com/bebanjo/persistize)
|
216
|
+
* [activerecord-denormalize](https://github.com/ursm/activerecord-denormalize)
|
217
|
+
* [flattery](https://github.com/evendis/flattery)
|
213
218
|
|
214
219
|
## License
|
215
220
|
* MIT
|
@@ -217,7 +222,18 @@ puts Employee.joins(branch: :company).where(companies: { id: company.id })
|
|
217
222
|
## Developer Guide
|
218
223
|
* see [developer_guide.md](developer_guide.md)
|
219
224
|
|
225
|
+
## Contributing
|
226
|
+
* pull requests and forks are very much welcomed! :) Let me know if you find any bug! Thanks
|
227
|
+
|
228
|
+
1. Fork it
|
229
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
230
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
231
|
+
4. Push to the branch (git push origin my-new-feature)
|
232
|
+
5. Create new Pull Request
|
233
|
+
|
220
234
|
## Changelog
|
235
|
+
* 0.1.3
|
236
|
+
* fixed Quickery not always working properly because of Rails autoloading; fixed by eager loading all Models (`app/models/*/**/*.rb`)
|
221
237
|
* 0.1.2
|
222
238
|
* fixed require error for remnant debugging code: 'byebug'
|
223
239
|
* 0.1.1
|
data/Rakefile
CHANGED
File without changes
|
data/config.ru
CHANGED
File without changes
|
data/developer_guide.md
CHANGED
File without changes
|
data/gemfiles/.bundle/config
CHANGED
File without changes
|
data/gemfiles/rails_4.gemfile
CHANGED
File without changes
|
data/gemfiles/rails_5.gemfile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Quickery
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
# Need to eager load all models so that all quickery callbacks and dependencies will be considered
|
4
|
+
config.after_initialize do |app|
|
5
|
+
# unless Rails app is already set to eager_load
|
6
|
+
unless app.config.eager_load
|
7
|
+
models_load_path = File.join(Rails.root, 'app', 'models')
|
8
|
+
|
9
|
+
# copied from https://apidock.com/rails/Rails/Engine/eager_load%21/class
|
10
|
+
matcher = /\A#{Regexp.escape(models_load_path.to_s)}\/(.*)\.rb\Z/
|
11
|
+
Dir.glob("#{models_load_path}/**/*.rb").sort.each do |file|
|
12
|
+
app.require_dependency file.sub(matcher, '\1')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/quickery/version.rb
CHANGED
data/lib/quickery.rb
CHANGED
File without changes
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# Quickery
|
2
|
+
## Other Similar Gems Comparison
|
3
|
+
|
4
|
+
* [persistize v0.5.0](https://github.com/bebanjo/persistize) :
|
5
|
+
* Pros against Quickery:
|
6
|
+
* Flexible custom methods / dependencies
|
7
|
+
* supports `has_many` and `belongs_to` while Quickery only supports `belongs_to` (currently)
|
8
|
+
* Cons against Quickery:
|
9
|
+
* It is not documented, but you'll need to do `Rails.application.eager_load!` first or something similar, to first load all the models as otherwise defined `persistize` across the models will be autoloaded, and therefore will not work properly. Quickery already does this eager loading of models out of the box. For more info, see [lib/quickery/railtie.rb](lib/quickery/railtie.rb)
|
10
|
+
* loops through each children records and update each attribute which can get very slow with lots of children associated records, and therefore as many number of SQL UPDATE queries vs Quickery which uses `update_all` which is just one update query, and does not loop through children records:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
# app/models/project.rb
|
14
|
+
class Project < ActiveRecord::Base
|
15
|
+
has_many :tasks
|
16
|
+
end
|
17
|
+
|
18
|
+
# app/models/task.rb
|
19
|
+
class Task < ActiveRecord::Base
|
20
|
+
belongs_to :project
|
21
|
+
|
22
|
+
def project_name
|
23
|
+
project.name
|
24
|
+
end
|
25
|
+
|
26
|
+
persistize :project_name, depending_on: :project
|
27
|
+
end
|
28
|
+
|
29
|
+
# rails console
|
30
|
+
project = Project.create(name: 'someproject')
|
31
|
+
task_1 = Task.create(project: project)
|
32
|
+
task_2 = Task.create(project: project)
|
33
|
+
|
34
|
+
project.update(name: 'newprojectname')
|
35
|
+
# for as many number of tasks records that belongs to the `project` above, the `update` above will also have the same number of SQL update queries, and can be very slow:
|
36
|
+
# SQL (0.1ms) UPDATE "tasks" SET "project_name" = $1 WHERE "tasks"."id" = $2 [["project_name", "newprojectname"], ["id", 1]]
|
37
|
+
# SQL (0.1ms) UPDATE "tasks" SET "project_name" = $1 WHERE "tasks"."id" = $2 [["project_name", "newprojectname"], ["id", 2]]
|
38
|
+
```
|
39
|
+
|
40
|
+
* because you are using custom methods in persistize, every time you update any of the `depending_on` records, the methods you defined are executed even if the updated attribute/s are not depended upon by the methods: i.e. extending from `persistize` github page:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# app/models/project.rb
|
44
|
+
class Project < ActiveRecord::Base
|
45
|
+
has_many :tasks
|
46
|
+
end
|
47
|
+
|
48
|
+
# app/models/task.rb
|
49
|
+
class Task < ActiveRecord::Base
|
50
|
+
belongs_to :project
|
51
|
+
|
52
|
+
def project_name
|
53
|
+
puts "Task(id: #{id}) project_name has been executed"
|
54
|
+
project.name
|
55
|
+
end
|
56
|
+
|
57
|
+
persistize :project_name, depending_on: :project
|
58
|
+
end
|
59
|
+
|
60
|
+
# rails console
|
61
|
+
project = Project.create(name: 'someproject')
|
62
|
+
task_1 = Task.create(project: project)
|
63
|
+
task_2 = Task.create(project: project)
|
64
|
+
|
65
|
+
project.update(someotherattribute: 'somevalue')
|
66
|
+
# => Task(id: 1) project_name has been executed
|
67
|
+
# => Task(id: 2) project_name has been executed
|
68
|
+
```
|
69
|
+
|
70
|
+
* does not support nested associated dependencies for `belongs_to`, but only supports for nested associated dependencies for `has_many` (if using `through: `):
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# app/models/project.rb
|
74
|
+
class Project < ActiveRecord::Base
|
75
|
+
has_many :tasks
|
76
|
+
end
|
77
|
+
|
78
|
+
# app/models/task.rb
|
79
|
+
class Task < ActiveRecord::Base
|
80
|
+
belongs_to :project
|
81
|
+
has_many :subtasks
|
82
|
+
end
|
83
|
+
|
84
|
+
# app/models/subtask.rb
|
85
|
+
class Subtask < ActiveRecord::Base
|
86
|
+
belongs_to :task
|
87
|
+
|
88
|
+
def task_name
|
89
|
+
task.name
|
90
|
+
end
|
91
|
+
|
92
|
+
def task_project_name
|
93
|
+
task.project.name
|
94
|
+
end
|
95
|
+
|
96
|
+
# works as expected:
|
97
|
+
persistize :task_name, :depending_on => [:task]
|
98
|
+
# not supported:
|
99
|
+
persistize :task_project_name, :depending_on => { task: :project }
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
* [activerecord-denormalize v0.2.0](https://github.com/ursm/activerecord-denormalize) :
|
104
|
+
* Pros against Quickery:
|
105
|
+
* *possibly there are pros, but because I could not test this because it seems to not support Rails 4 and 5 (see cons below)*
|
106
|
+
* Cons against Quickery:
|
107
|
+
* Rails 5 seems to be not supported (most likely because last commit was 6 years ago). I was getting `Gem Load Error is: wrong number of arguments (given 0, expected 1)` when doing `rails g model message sender:references{polymorphic} _sender:hstore`
|
108
|
+
* Rails 4 seems to be also not supported. I was getting `ArgumentError (wrong number of arguments (given 1, expected 0))` when doing `User.create` inside rails console.
|
109
|
+
|
110
|
+
* [flattery v0.1.0](https://github.com/evendis/flattery) :
|
111
|
+
* Pros against Quickery:
|
112
|
+
* allows custom update method
|
113
|
+
* allows "updates" as a background process
|
114
|
+
* Cons against Quickery:
|
115
|
+
* Rails 5 is not part of its supported list in their github page. And just to try it out on a Rails 5 app, `Flattery::ValueProvider` did not seem to work, because values are not pushed to the `:notes`'s `:category_name` values.
|
116
|
+
* Using Rails 4, does not support nested associated dependencies for `belongs_to`:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
class Note < ActiveRecord::Base
|
120
|
+
belongs_to :category, :inverse_of => :notes
|
121
|
+
|
122
|
+
include Flattery::ValueCache
|
123
|
+
# one-level works:
|
124
|
+
flatten_value category: :name
|
125
|
+
# nested not supported:
|
126
|
+
flatten_value category: { user: :email }
|
127
|
+
end
|
128
|
+
```
|
data/quickery.gemspec
CHANGED
File without changes
|
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: 0.1.
|
4
|
+
version: 0.1.3
|
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-09-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -238,7 +238,9 @@ files:
|
|
238
238
|
- lib/quickery/association_builder.rb
|
239
239
|
- lib/quickery/callbacks_builder.rb
|
240
240
|
- lib/quickery/quickery_builder.rb
|
241
|
+
- lib/quickery/railtie.rb
|
241
242
|
- lib/quickery/version.rb
|
243
|
+
- other_similar_gems_comparison.md
|
242
244
|
- quickery.gemspec
|
243
245
|
homepage: https://github.com/jrpolidario/quickery
|
244
246
|
licenses:
|