active_hash 3.1.1 → 3.2.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/CHANGELOG.md +353 -0
- data/README.md +11 -8
- data/active_hash.gemspec +8 -1
- data/lib/active_file/base.rb +11 -4
- data/lib/active_file/hash_and_array_files.rb +1 -1
- data/lib/active_hash/base.rb +26 -49
- data/lib/active_hash/condition.rb +44 -0
- data/lib/active_hash/conditions.rb +21 -0
- data/lib/active_hash/relation.rb +103 -78
- data/lib/active_hash/version.rb +1 -1
- data/lib/active_hash.rb +2 -0
- data/lib/active_yaml/base.rb +10 -2
- data/lib/associations/associations.rb +24 -14
- data/lib/associations/reflection_extensions.rb +25 -0
- metadata +12 -5
- data/CHANGELOG +0 -242
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11f2e4807b50cf0708d0a9ca9bea56e9a26bc9b7ca7eb2e81e0a93f88c333c7e
|
|
4
|
+
data.tar.gz: ba9dee0fea4fa0e02b8ebc2eae74839e72f1e2ea1fd262606561e42aac10ecf1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f7d4c59c9087aaddd26c05295507850f9720ba14b60cdfeb4c77bfbcefd43d982fb052212dc89e6fd5c0d753de047d512d1ce7d5ce3644dc9dd89efa166066d
|
|
7
|
+
data.tar.gz: ec31d53f5622c6b2a8958656b9ac035d00c2484b7d7ee8cd6b486ad6a9c1351ad1d55fbda487025b268ee708688ba832b0513189b91db773956eaea5ba2c2737
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# active_hash Changelog
|
|
2
|
+
|
|
3
|
+
## Version [3.2.0] - <sub><sup>2022-07-14</sup></sub>
|
|
4
|
+
|
|
5
|
+
- Add Ruby 3.2 to the CI matrix [#275](https://github.com/active-hash/active_hash/pull/275) @petergoldstein
|
|
6
|
+
- Handle default value of `false` [#274](https://github.com/active-hash/active_hash/pull/274) @ihollander
|
|
7
|
+
- Run CI only one time per commit [#273](https://github.com/active-hash/active_hash/pull/273) @flavorjones
|
|
8
|
+
- Rails 7 support [#272](https://github.com/active-hash/active_hash/pull/272) @flavorjones
|
|
9
|
+
- Avoid interfere with AR's belongs_to arguments. [#270](https://github.com/active-hash/active_hash/pull/270) @koyo-miyamura
|
|
10
|
+
- Fix broken #pluck method with 3+ attrs specified [#269](https://github.com/active-hash/active_hash/pull/269) @h6ah4i
|
|
11
|
+
- Fix relations for Rails 7 support, and not modifying conditions [#268](https://github.com/active-hash/active_hash/pull/268) @pfeiffer
|
|
12
|
+
- docs: Remove the string 'F' [#264](https://github.com/active-hash/active_hash/pull/264) @tbotaq
|
|
13
|
+
- Show example using regex in where query [#263](https://github.com/active-hash/active_hash/pull/263) @scottharvey
|
|
14
|
+
- Improve performance of exists? [#262](https://github.com/active-hash/active_hash/pull/262) @ise-tang
|
|
15
|
+
- Remove redundant ActiveRecord version check [#260](https://github.com/active-hash/active_hash/pull/260) @yujideveloper
|
|
16
|
+
- Fix deprecation warnings [#259](https://github.com/active-hash/active_hash/pull/259) @yujideveloper
|
|
17
|
+
- Fix rspec config when SKIP_ACTIVE_RECORD enabled [#258](https://github.com/active-hash/active_hash/pull/258) @yujideveloper
|
|
18
|
+
- isolate tests with temporary classes [#256](https://github.com/active-hash/active_hash/pull/256) @machisuke
|
|
19
|
+
- Avoid ActiveRecordExtensions affects AR's belongs_to method. [#255](https://github.com/active-hash/active_hash/pull/255) @machisuke
|
|
20
|
+
- add option to disable erb parsing [#202](https://github.com/active-hash/active_hash/pull/202) @reedlaw
|
|
21
|
+
- add collection singular ids for associations [#237](https://github.com/active-hash/active_hash/pull/237) @1160054
|
|
22
|
+
- Fix the thread-safe spec for the updated cities fixture @adampal
|
|
23
|
+
- Add thread-safety to ActiveFile [#229](https://github.com/active-hash/active_hash/pull/229) @dmitriy-kiriyenko
|
|
24
|
+
|
|
25
|
+
## Version [3.1.1] - <sub><sup>2022-07-14</sup></sub>
|
|
26
|
+
|
|
27
|
+
- Make scopes chainable [#248](https://github.com/active-hash/active_hash/pull/248) @andreynering
|
|
28
|
+
- Set default key attributes [#251](https://github.com/active-hash/active_hash/pull/251/commits/68a0a121d110ac83f4bbf0024f027714fd24debf) @adampal
|
|
29
|
+
- Migrate from Travis to GitHub Actions for CI @kbrock
|
|
30
|
+
- Add primary_key support for has_one [#218](https://github.com/active-hash/active_hash/pull/218) @yujideveloper
|
|
31
|
+
- Return a chainable relation when using .not [#205](https://github.com/active-hash/active_hash/pull/205) @pfeiffer
|
|
32
|
+
- Correct fields with YAML aliases in array style [#226](https://github.com/active-hash/active_hash/pull/226) @stomk
|
|
33
|
+
- Add ActiveHash::Relation#size method for compatibily [#227](https://github.com/active-hash/active_hash/pull/227) @sluceno
|
|
34
|
+
- Implement ActiveRecord::RecordNotFound interface [#207](https://github.com/active-hash/active_hash/pull/207) @ChrisBr
|
|
35
|
+
- Fix find_by_id with filter chain [#210](https://github.com/active-hash/active_hash/pull/210) @ChrisBr
|
|
36
|
+
- Suppress Ruby 2.7 kwargs warnings [#206](https://github.com/active-hash/active_hash/pull/206) @yhirano55
|
|
37
|
+
- Call reload if @records is not defined [#208](https://github.com/active-hash/active_hash/pull/208) @jonmagic
|
|
38
|
+
- Switch to rspec3 (and update the Gemfile) [#209](https://github.com/active-hash/active_hash/pull/209) @djberg96
|
|
39
|
+
- Implement filter by RegEx [#211](https://github.com/active-hash/active_hash/pull/211) @ChrisBr
|
|
40
|
+
- Supports .pick method [#195](https://github.com/active-hash/active_hash/pull/195/files) @yhirano55
|
|
41
|
+
- Lots of other small performance improvements, documentation and testing. Thanks to everyone who contributed!
|
|
42
|
+
|
|
43
|
+
## Version [3.1.0] - <sub><sup>2020-01-15</sup></sub>
|
|
44
|
+
|
|
45
|
+
- Add ActiveHash::Base.order method inspired by ActiveRecord [#177](https://github.com/active-hash/active_hash/pull/177)
|
|
46
|
+
- Add #to_ary to ActiveHash::Relation [#182](https://github.com/active-hash/active_hash/pull/182)
|
|
47
|
+
- Allow #find to behave like Enumerable#find if id is nil and a block is given [#183](https://github.com/active-hash/active_hash/pull/183)
|
|
48
|
+
- Delegate :sample to `records` [#189](https://github.com/active-hash/active_hash/pull/189)
|
|
49
|
+
|
|
50
|
+
## Version [3.0.0] - <sub><sup>2019-09-28</sup></sub>
|
|
51
|
+
|
|
52
|
+
- Make #where chainable [#178](https://github.com/active-hash/active_hash/pull/178)
|
|
53
|
+
|
|
54
|
+
## Version [2.3.0] - <sub><sup>2019-09-28</sup></sub>
|
|
55
|
+
|
|
56
|
+
- Add ::scope method (inspired by ActiveRecord) [#173](https://github.com/active-hash/active_hash/pull/173)
|
|
57
|
+
- Let `.find(nil)` raise ActiveHash::RecordNotFound (inspired by ActiveRecord) [#174](https://github.com/active-hash/active_hash/pull/174)
|
|
58
|
+
- `where` clause now works with range argument [#175](https://github.com/active-hash/active_hash/pull/175)
|
|
59
|
+
|
|
60
|
+
## Version [2.2.1] - <sub><sup>2019-03-06</sup></sub>
|
|
61
|
+
|
|
62
|
+
- Allow empty YAML [#171](https://github.com/active-hash/active_hash/pull/171) Thanks, @ppworks
|
|
63
|
+
|
|
64
|
+
## Version [2.2.0] - <sub><sup>2018-11-22</sup></sub>
|
|
65
|
+
|
|
66
|
+
- Support pluck method [#164](https://github.com/active-hash/active_hash/pull/164) Thanks, @ihatov08
|
|
67
|
+
- Support where.not method [#167](https://github.com/active-hash/active_hash/pull/167) Thanks, @DialBird
|
|
68
|
+
|
|
69
|
+
## Version [2.1.0] - <sub><sup>2018-04-05</sup></sub>
|
|
70
|
+
|
|
71
|
+
- Allow to use ERB (embedded ruby) in yml files [#160](https://github.com/active-hash/active_hash/pull/160) Thanks, @UgoMare
|
|
72
|
+
- Add `ActiveHash::Base.polymorphic_name` [#162](https://github.com/active-hash/active_hash/pull/162)
|
|
73
|
+
- Fix to be able to use enum accessor constant with same name as top-level constant[#161](https://github.com/active-hash/active_hash/pull/161) Thanks, @yujideveloper
|
|
74
|
+
|
|
75
|
+
## Version [2.0.0] - <sub><sup>2018-02-27</sup></sub>
|
|
76
|
+
|
|
77
|
+
- Drop old Ruby and Rails support [#157](https://github.com/active-hash/active_hash/pull/157)
|
|
78
|
+
- Don't generate instance accessors for class attributes [#136](https://github.com/active-hash/active_hash/pull/136) Thanks, @rainhead
|
|
79
|
+
|
|
80
|
+
## Version [1.5.3] - <sub><sup>2017-06-14</sup></sub>
|
|
81
|
+
|
|
82
|
+
- Support symbol values in where and find_by [#156](https://github.com/active-hash/active_hash/pull/156) Thanks, @south37
|
|
83
|
+
|
|
84
|
+
## Version [1.5.2] - <sub><sup>2017-06-14</sup></sub>
|
|
85
|
+
|
|
86
|
+
- Fix find_by when passed an invalid id [#152](https://github.com/active-hash/active_hash/pull/152) Thanks, @davidstosik
|
|
87
|
+
|
|
88
|
+
## Version [1.5.1] - <sub><sup>2017-04-20</sup></sub>
|
|
89
|
+
|
|
90
|
+
- Fix a bug on `.where` [#147](https://github.com/active-hash/active_hash/pull/147)
|
|
91
|
+
|
|
92
|
+
## Version [1.5.0] - <sub><sup>2017-03-24</sup></sub>
|
|
93
|
+
|
|
94
|
+
- add support for `.find_by!`(@syguer)
|
|
95
|
+
|
|
96
|
+
## Version [1.4.1] - <sub><sup>2015-09-13</sup></sub>
|
|
97
|
+
|
|
98
|
+
- fix bug where `#attributes` didn't contain default values [#107](https://github.com/active-hash/active_hash/pull/107)
|
|
99
|
+
- add support for `.find_by` and `#_read_attribute`. Thanks, @andrewfader
|
|
100
|
+
|
|
101
|
+
## Version [1.4.0] - <sub><sup>2014-09-03</sup></sub>
|
|
102
|
+
|
|
103
|
+
- support Rails 4.2 @agraves, @al2o3cr
|
|
104
|
+
|
|
105
|
+
## Version [1.3.0] - <sub><sup>2014-02-18</sup></sub>
|
|
106
|
+
|
|
107
|
+
- fix bug where including ActiveHash associations would make `belongs_to :imageable, polymorphic: true` blow up
|
|
108
|
+
- fixed several bugs that prevented active hash from being used without active record / active model
|
|
109
|
+
- add support for splitting up data sources into multiple files @rheaton
|
|
110
|
+
- add support for storing data in json files @rheaton
|
|
111
|
+
|
|
112
|
+
## Version [1.2.3] - <sub><sup>2013-11-29</sup></sub>
|
|
113
|
+
|
|
114
|
+
- fix bug where active hash would call `.all` on models when setting has_many @grosser
|
|
115
|
+
|
|
116
|
+
## Version [1.2.2] - <sub><sup>2013-11-05</sup></sub>
|
|
117
|
+
|
|
118
|
+
- fix bug in gemspec that made it impossible to use w/ Rails 4
|
|
119
|
+
|
|
120
|
+
## Version [1.2.1] - <sub><sup>2013-10-24</sup></sub>
|
|
121
|
+
|
|
122
|
+
- fixed nasty bug in belongs_to that would prevent users from passing procs @freebird0221
|
|
123
|
+
- fixed bug where passing in a separate class name to belongs_to_active_hash would raise an exception @mauriciopasquier
|
|
124
|
+
|
|
125
|
+
## Version [1.2.0] - <sub><sup>2013-10-01</sup></sub>
|
|
126
|
+
|
|
127
|
+
- belongs_to is back!
|
|
128
|
+
- added support for primary key options for belongs_to @tomtaylor
|
|
129
|
+
|
|
130
|
+
## Version [1.0.2] - <sub><sup>2013-09-09</sup></sub>
|
|
131
|
+
|
|
132
|
+
- `where(nil)` returns all results, like ActiveRecord @kugaevsky
|
|
133
|
+
|
|
134
|
+
## Version [1.0.1] - <sub><sup>2013-07-15</sup></sub>
|
|
135
|
+
|
|
136
|
+
- Travis CI for ActiveHash + Ruby 2, 1.8.7, Rubinius and JRuby support @mattheworiordan
|
|
137
|
+
- no longer need to call .all before executing `find_by_*` or `where` methods @mattheworiordan
|
|
138
|
+
|
|
139
|
+
## Version [1.0.0] - <sub><sup>2013-06-24</sup></sub>
|
|
140
|
+
|
|
141
|
+
- save is a no-op on existing records, instead of raising an error (issue #63)
|
|
142
|
+
|
|
143
|
+
## Version [0.10.0] - <sub><sup>2013-06-24</sup></sub>
|
|
144
|
+
|
|
145
|
+
- added ActiveYaml::Aliases module so you can DRY up your repetitive yaml @brett-richardson
|
|
146
|
+
|
|
147
|
+
## Version [0.9.14] - <sub><sup>2013-05-23</sup></sub>
|
|
148
|
+
|
|
149
|
+
- enum_accessor can now take multiple field names when generating the constant
|
|
150
|
+
- temporarily disabled rails edge specs since there's an appraisal issue with minitest
|
|
151
|
+
|
|
152
|
+
## Version [0.9.13] <sub><sup>2013-01-22</sup></sub>
|
|
153
|
+
- Fix find_by_id and find method returning nil unless .all called in ActiveYaml @mattheworiordan
|
|
154
|
+
|
|
155
|
+
## Version [0.9.12] <sub><sup>2012-07-25</sup></sub>
|
|
156
|
+
- Make find_by_id lookups faster by indexing records by id @desmondmonster
|
|
157
|
+
|
|
158
|
+
## Version [0.9.11] <sub><sup>2012-07-16</sup></sub>
|
|
159
|
+
- Validate IDs are unique by caching them in a set @desmondmonster
|
|
160
|
+
|
|
161
|
+
## Version [0.9.10] <sub><sup>2012-04-14</sup></sub>
|
|
162
|
+
- Support for has_one associations @kbrock
|
|
163
|
+
|
|
164
|
+
## Version [0.9.9] <sub><sup>2012-04-05</sup></sub>
|
|
165
|
+
|
|
166
|
+
- Allow gems like simple_form to read metadata about belongs_to associations that point to active hash objects @kbrock
|
|
167
|
+
- Move specs to appraisal @flavorjones
|
|
168
|
+
|
|
169
|
+
## Version [0.9.8] - <sub><sup>2012-01-18</sup></sub>
|
|
170
|
+
|
|
171
|
+
- Make ActiveHash.find with array raise an exception when record cannot be found @mocoso
|
|
172
|
+
|
|
173
|
+
## Version [0.9.7] - <sub><sup>2011-09-18</sup></sub>
|
|
174
|
+
|
|
175
|
+
- Fixing the setting of a `belongs_to_active_hash` association by association (not id).
|
|
176
|
+
|
|
177
|
+
## Version [0.9.6] - <sub><sup>2011-08-31</sup></sub>
|
|
178
|
+
- added a module which adds a .belongs_to_active_hash method to ActiveRecord, since it was broken for Rails 3.1 @felixclack
|
|
179
|
+
|
|
180
|
+
## Version [0.9.5] - <sub><sup>2011-06-07</sup></sub>
|
|
181
|
+
- fixed bug where .find would not work if you defined your ids as strings
|
|
182
|
+
|
|
183
|
+
## Version [0.9.4] - <sub><sup>2011-06-05</sup></sub>
|
|
184
|
+
- fixed deprecation warnings for class_inheritable_accessor @scudco
|
|
185
|
+
- added basic compatibility with the `where` method from Arel @rgarver
|
|
186
|
+
|
|
187
|
+
## Version [0.9.3] - <sub><sup>2011-04-19</sup></sub>
|
|
188
|
+
- better dependency management and compatibility with ActiveSupport 2.x @vandrijevik
|
|
189
|
+
|
|
190
|
+
## Version [0.9.2] - <sub><sup>2011-01-22</sup></sub>
|
|
191
|
+
- improved method_missing errors for dynamic finders
|
|
192
|
+
- prevent users from trying to overwrite :attributes [#33](https://github.com/active-hash/active_hash/issues/33)
|
|
193
|
+
|
|
194
|
+
## Version [0.9.1] <sub><sup>2010-12-08</sup></sub>
|
|
195
|
+
- ruby 1.9.2 compatibility
|
|
196
|
+
|
|
197
|
+
## Version [0.9.0] <sub><sup>2010-12-06</sup></sub>
|
|
198
|
+
- added dependency on ActiveModel
|
|
199
|
+
- add persisted? method to ActiveHash::Base
|
|
200
|
+
- ActiveHash::Base#save takes \*args to be compatible with ActiveModel
|
|
201
|
+
- ActiveHash::Base#to_param returns nil if the object hasn't been saved
|
|
202
|
+
|
|
203
|
+
## Version [0.8.7] <sub><sup>2010-11-09</sup></sub>
|
|
204
|
+
- Use Ruby's definition of "word character" (numbers, underscores) when forming ActiveHash::Enum constants @tstuart
|
|
205
|
+
|
|
206
|
+
## Version [0.8.6] <sub><sup>2010-11-07</sup></sub>
|
|
207
|
+
- Get ActiveHash::Associations to return a scope for has_many active record relationships @mocoso
|
|
208
|
+
|
|
209
|
+
## Version [0.8.5] <sub><sup>2010-10-20</sup></sub>
|
|
210
|
+
- Allow find_by_* methods to accept an options hash, so rails associations don't blow up
|
|
211
|
+
|
|
212
|
+
## Version [0.8.4] <sub><sup>2010-10-07</sup></sub>
|
|
213
|
+
- Add conditions to ActiveHash#all (Ryan Garver)
|
|
214
|
+
- Add #cache_key to ActiveHash::Base (Tom Stuart)
|
|
215
|
+
- Add banged dynamic finder support to ActiveHash::Base (Tom Stuart)
|
|
216
|
+
|
|
217
|
+
## Version [0.8.3] <sub><sup>2010-09-16</sup></sub>
|
|
218
|
+
- Enum format now uses underscores instead of removing all characters
|
|
219
|
+
- Removed test dependency on acts_as_fu
|
|
220
|
+
|
|
221
|
+
## Version [0.8.2] <sub><sup>2010-05-26</sup></sub>
|
|
222
|
+
- Silence metaclass deprecation warnings in active support 2.3.8
|
|
223
|
+
|
|
224
|
+
## Version [0.8.1] <sub><sup>2010-05-04</sup></sub>
|
|
225
|
+
- When calling ActiveFile::Base.reload do not actually perform the reload if nothing has been modified unless you call reload(true) to force (Michael Schubert)
|
|
226
|
+
|
|
227
|
+
## Version [0.8.0] <sub><sup>2010-04-25</sup></sub>
|
|
228
|
+
- When ActiveRecord model belongs_to an ActiveHash and the associated id is nil, returns nil instead of raising RecordNotFound (Jeremy Weiskotten)
|
|
229
|
+
- Merged Nakajima's "add" alias for "create" - gotta save those ASCII characters :)
|
|
230
|
+
|
|
231
|
+
## Version [0.7.9] <sub><sup>2010-03-01</sup></sub>
|
|
232
|
+
- Removed "extend"-related deprecations - they didn't play well with rails class loading
|
|
233
|
+
|
|
234
|
+
## Version [0.7.8] <sub><sup>2010-01-18</sup></sub>
|
|
235
|
+
- Added stub for #destroyed? method, since Rails associations now depend on it
|
|
236
|
+
|
|
237
|
+
## Version [0.7.7] <sub><sup>2009-12-19</sup></sub>
|
|
238
|
+
- Deprecated include ActiveHash::Associations in favor of extend ActiveHash::Associations
|
|
239
|
+
|
|
240
|
+
## Version [0.7.6] <sub><sup>2009-12-19</sup></sub>
|
|
241
|
+
- Added ActiveHash::Enum (John Pignata)
|
|
242
|
+
- Fixed bug where you can't set nil to an association
|
|
243
|
+
- Calling #belongs_to now creates the underlying field if it's not already there (belongs_to :city will create the :city_id field)
|
|
244
|
+
|
|
245
|
+
## Version [0.7.5] <sub><sup>2009-12-10</sup></sub>
|
|
246
|
+
- Fixed a bug where belongs_to associations would raise an error instead of returning nil when the parent object didn't exist.
|
|
247
|
+
- Added #[] and #[]= accessors for more ActiveRecord-esque-ness. (Pat Nakajima & Dave Yeu)
|
|
248
|
+
|
|
249
|
+
## Version [0.7.4] <sub><sup>2009-12-01</sup></sub>
|
|
250
|
+
- Add marked_for_destruction? to be compatible with nested attributes (Brandon Keene)
|
|
251
|
+
- Added second parameter to respond_to? and cleaned up specs (Brian Takita)
|
|
252
|
+
- Find with an id that does not exist now raises a RecordNotFound exception to mimic ActiveRecord (Pat Nakajima)
|
|
253
|
+
|
|
254
|
+
## Version [0.7.3] <sub><sup>2009-10-22</sup></sub>
|
|
255
|
+
- added setters to ActiveHash::Base for all fields
|
|
256
|
+
- instantiating an ActiveHash object with a hash calls the setter methods on the object
|
|
257
|
+
- boolean default values now work
|
|
258
|
+
|
|
259
|
+
## Version [0.7.2] <sub><sup>2009-10-21</sup></sub>
|
|
260
|
+
- Removed auto-reloading of files based on mtime - maybe it will come back later
|
|
261
|
+
- Made ActiveFile::Base.all a bit more sane
|
|
262
|
+
|
|
263
|
+
## Version 0.7.1 <sub><sup>2009-10-13</sup></sub>
|
|
264
|
+
- added ActiveHash::Base.has_many, which works with ActiveRecord or ActiveHash classes @baldwindavid
|
|
265
|
+
- added ActiveHash::Base.belongs_to, which works with ActiveRecord or ActiveHash classes @baldwindavid
|
|
266
|
+
- added .delete_all method that clears the in-memory array
|
|
267
|
+
- added support for Hash-style yaml (think, Rails fixtures)
|
|
268
|
+
- added setter for parent object on belongs_to ( `city = City.new; city.state = State.first; city.state_id == State.first.id` )
|
|
269
|
+
|
|
270
|
+
## Version [0.7.0] <sub><sup>2009-10-12</sup></sub>
|
|
271
|
+
- auto-assign fields after calling data= instead of after calling .all
|
|
272
|
+
- remove require 'rubygems', so folks with non-gem setups can still use AH
|
|
273
|
+
- added more specific activesupport dependency to ensure that metaclass is available
|
|
274
|
+
- AH no longer calls to_i on ids. If you pass in a string as an id, you'll get a string back
|
|
275
|
+
- Fancy finders, such as find_all_by_id_and_name, will compare the to_s values of the fields, so you can pass in strings
|
|
276
|
+
- You can now use ActiveHash models as the parents of polymorphic belongs_to associations
|
|
277
|
+
- save, save!, create and create! now add items to the in-memory collection, and naively adds autoincrementing id
|
|
278
|
+
- new_record? returns false if the record is part of the collection
|
|
279
|
+
- ActiveHash now works with Fixjour!
|
|
280
|
+
|
|
281
|
+
## Version [0.6.1] <sub><sup>2009-08-19</sup></sub>
|
|
282
|
+
- Added custom finders for multiple fields, such as .find_all_by_name_and_age
|
|
283
|
+
|
|
284
|
+
## Version 0.5.0 <sub><sup>2009-07-23</sup></sub>
|
|
285
|
+
- Added support for auto-defining methods based on hash keys in ActiveHash::Base
|
|
286
|
+
- Changed the :field and :fields API so that they don't overwrite existing methods (useful when ActiveHash auto-defines methods)
|
|
287
|
+
- Fixed a bug where ActiveFile incorrectly set the root_path to be the path in the gem directory, not the current working directory
|
|
288
|
+
|
|
289
|
+
## Version 0.4.0 <sub><sup>2009-07-24</sup></sub>
|
|
290
|
+
- ActiveFile no longer reloads files by default
|
|
291
|
+
- Added ActiveFile.reload_active_file= so you can cause ActiveFile to reload
|
|
292
|
+
- Setting data to nil correctly causes .all to return an empty array
|
|
293
|
+
- Added reload(force) method, so that you can force a reload from files in ActiveFile, useful for tests
|
|
294
|
+
|
|
295
|
+
[HEAD]: https://github.com/active-hash/active_hash/compare/v4.3.0...HEAD
|
|
296
|
+
[4.3.0]: https://github.com/active-hash/active_hash/compare/v3.2.0...v4.3.0
|
|
297
|
+
[4.2.0]: https://github.com/active-hash/active_hash/compare/v3.1.1...v4.2.0
|
|
298
|
+
[3.1.1]: https://github.com/active-hash/active_hash/compare/v3.1.0...v3.1.1
|
|
299
|
+
[3.1.0]: https://github.com/active-hash/active_hash/compare/v3.0.0...v3.1.0
|
|
300
|
+
[3.0.0]: https://github.com/active-hash/active_hash/compare/v2.3.0...v3.0.0
|
|
301
|
+
[2.3.0]: https://github.com/active-hash/active_hash/compare/v2.2.1...v2.3.0
|
|
302
|
+
[2.2.1]: https://github.com/active-hash/active_hash/compare/v2.2.0...v2.2.1
|
|
303
|
+
[2.2.0]: https://github.com/active-hash/active_hash/compare/v2.1.0...v2.2.0
|
|
304
|
+
[2.1.0]: https://github.com/active-hash/active_hash/compare/v2.0.0...v2.1.0
|
|
305
|
+
[2.0.0]: https://github.com/active-hash/active_hash/compare/v1.5.3...v2.0.0
|
|
306
|
+
[1.5.3]: https://github.com/active-hash/active_hash/compare/v1.5.2...v1.5.3
|
|
307
|
+
[1.5.2]: https://github.com/active-hash/active_hash/compare/v1.5.1...v1.5.2
|
|
308
|
+
[1.5.1]: https://github.com/active-hash/active_hash/compare/v1.5.0...v1.5.1
|
|
309
|
+
[1.5.0]: https://github.com/active-hash/active_hash/compare/v1.4.1...v1.5.0
|
|
310
|
+
[1.4.1]: https://github.com/active-hash/active_hash/compare/v1.4.0...v1.4.1
|
|
311
|
+
[1.4.0]: https://github.com/active-hash/active_hash/compare/v1.3.0...v1.4.0
|
|
312
|
+
[1.3.0]: https://github.com/active-hash/active_hash/compare/v1.2.3...v1.3.0
|
|
313
|
+
[1.2.3]: https://github.com/active-hash/active_hash/compare/v1.2.2...v1.2.3
|
|
314
|
+
[1.2.2]: https://github.com/active-hash/active_hash/compare/v1.2.1...v1.2.2
|
|
315
|
+
[1.2.1]: https://github.com/active-hash/active_hash/compare/v1.2.0...v1.2.1
|
|
316
|
+
[1.2.0]: https://github.com/active-hash/active_hash/compare/v1.0.2...v1.2.0
|
|
317
|
+
[1.0.2]: https://github.com/active-hash/active_hash/compare/v1.0.1...v1.0.2
|
|
318
|
+
[1.0.1]: https://github.com/active-hash/active_hash/compare/v1.0.0...v1.0.1
|
|
319
|
+
[1.0.0]: https://github.com/active-hash/active_hash/compare/v0.10.0...v1.0.0
|
|
320
|
+
[0.10.0]: https://github.com/active-hash/active_hash/compare/v0.9.14...v0.10.0
|
|
321
|
+
[0.9.14]: https://github.com/active-hash/active_hash/compare/v0.9.13...v0.9.14
|
|
322
|
+
[0.9.13]: https://github.com/active-hash/active_hash/compare/v0.9.12...v0.9.13
|
|
323
|
+
[0.9.12]: https://github.com/active-hash/active_hash/compare/v0.9.11...v0.9.12
|
|
324
|
+
[0.9.11]: https://github.com/active-hash/active_hash/compare/v0.9.10...v0.9.11
|
|
325
|
+
[0.9.10]: https://github.com/active-hash/active_hash/compare/v0.9.9...v0.9.10
|
|
326
|
+
[0.9.9]: https://github.com/active-hash/active_hash/compare/v0.9.8...v0.9.9
|
|
327
|
+
[0.9.8]: https://github.com/active-hash/active_hash/compare/v0.9.7...v0.9.8
|
|
328
|
+
[0.9.7]: https://github.com/active-hash/active_hash/compare/v0.9.6...v0.9.7
|
|
329
|
+
[0.9.6]: https://github.com/active-hash/active_hash/compare/v0.9.5...v0.9.6
|
|
330
|
+
[0.9.5]: https://github.com/active-hash/active_hash/compare/v0.9.4...v0.9.5
|
|
331
|
+
[0.9.4]: https://github.com/active-hash/active_hash/compare/v0.9.3...v0.9.4
|
|
332
|
+
[0.9.3]: https://github.com/active-hash/active_hash/compare/v0.9.2...v0.9.3
|
|
333
|
+
[0.9.2]: https://github.com/active-hash/active_hash/compare/v0.9.1...v0.9.2
|
|
334
|
+
[0.9.1]: https://github.com/active-hash/active_hash/compare/v0.9.0...v0.9.1
|
|
335
|
+
[0.9.0]: https://github.com/active-hash/active_hash/compare/v0.8.7...v0.9.0
|
|
336
|
+
[0.8.7]: https://github.com/active-hash/active_hash/compare/v0.8.6...v0.8.7
|
|
337
|
+
[0.8.6]: https://github.com/active-hash/active_hash/compare/v0.8.5...v0.8.6
|
|
338
|
+
[0.8.5]: https://github.com/active-hash/active_hash/compare/v0.8.4...v0.8.5
|
|
339
|
+
[0.8.4]: https://github.com/active-hash/active_hash/compare/v0.8.3...v0.8.4
|
|
340
|
+
[0.8.3]: https://github.com/active-hash/active_hash/compare/v0.8.2...v0.8.3
|
|
341
|
+
[0.8.2]: https://github.com/active-hash/active_hash/compare/v0.8.1...v0.8.2
|
|
342
|
+
[0.8.1]: https://github.com/active-hash/active_hash/compare/v0.8.0...v0.8.1
|
|
343
|
+
[0.8.0]: https://github.com/active-hash/active_hash/compare/v0.7.9...v0.8.0
|
|
344
|
+
[0.7.9]: https://github.com/active-hash/active_hash/compare/v0.7.8...v0.7.9
|
|
345
|
+
[0.7.8]: https://github.com/active-hash/active_hash/compare/v0.7.7...v0.7.8
|
|
346
|
+
[0.7.7]: https://github.com/active-hash/active_hash/compare/v0.7.6...v0.7.7
|
|
347
|
+
[0.7.6]: https://github.com/active-hash/active_hash/compare/v0.7.5...v0.7.6
|
|
348
|
+
[0.7.5]: https://github.com/active-hash/active_hash/compare/v0.7.4...v0.7.5
|
|
349
|
+
[0.7.4]: https://github.com/active-hash/active_hash/compare/v0.7.3...v0.7.4
|
|
350
|
+
[0.7.3]: https://github.com/active-hash/active_hash/compare/v0.7.2...v0.7.3
|
|
351
|
+
[0.7.2]: https://github.com/active-hash/active_hash/compare/v0.7.0...v0.7.2
|
|
352
|
+
[0.7.0]: https://github.com/active-hash/active_hash/compare/v0.6.1...v0.7.0
|
|
353
|
+
[0.6.1]: https://github.com/active-hash/active_hash/compare/v0.6.0...v0.6.1
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ ActiveHash also ships with:
|
|
|
14
14
|
|
|
15
15
|
* ActiveFile: a base class that you can use to create file data sources
|
|
16
16
|
* ActiveYaml: a base class that will turn YAML into a hash and load the data into an ActiveHash object
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
## !!! Important notice !!!
|
|
19
19
|
We have changed returned value to chainable by v3.0.0. It's not just an `Array` instance anymore.
|
|
20
20
|
If it breaks your application, please report us on [issues](https://github.com/active-hash/active_hash/issues), and use v2.x.x as following..
|
|
@@ -169,6 +169,7 @@ Country.find_by_id 1 # => find the first object that matches the id
|
|
|
169
169
|
Country.find_by(name: 'US') # => returns the first country object with specified argument
|
|
170
170
|
Country.find_by!(name: 'US') # => same as find_by, but raise exception when not found
|
|
171
171
|
Country.where(name: 'US') # => returns all records with name: 'US'
|
|
172
|
+
Country.where(name: /U/) # => returns all records where the name matches the regex /U/
|
|
172
173
|
Country.where.not(name: 'US') # => returns all records without name: 'US'
|
|
173
174
|
Country.order(name: :desc) # => returns all records ordered by name attribute in DESC order
|
|
174
175
|
```
|
|
@@ -211,11 +212,11 @@ Country#name= # => sets the name
|
|
|
211
212
|
The ActiveHash::Base.all method functions like an in-memory data store. You can save your records as ActiveHash::Relation object by using standard ActiveRecord create and save methods:
|
|
212
213
|
```ruby
|
|
213
214
|
Country.all
|
|
214
|
-
=> #<ActiveHash::Relation:0x00007f861e043bb0 @klass=Country, @all_records=[], @
|
|
215
|
+
=> #<ActiveHash::Relation:0x00007f861e043bb0 @klass=Country, @all_records=[], @conditions=[..], @records_dirty=false>
|
|
215
216
|
Country.create
|
|
216
217
|
=> #<Country:0x00007f861b7abce8 @attributes={:id=>1}>
|
|
217
218
|
Country.all
|
|
218
|
-
=> #<ActiveHash::Relation:0x00007f861b7b3628 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>], @
|
|
219
|
+
=> #<ActiveHash::Relation:0x00007f861b7b3628 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>], @conditions=[..], @records_dirty=false>
|
|
219
220
|
country = Country.new
|
|
220
221
|
=> #<Country:0x00007f861e059938 @attributes={}>
|
|
221
222
|
country.new_record?
|
|
@@ -225,7 +226,7 @@ country.save
|
|
|
225
226
|
country.new_record?
|
|
226
227
|
# => false
|
|
227
228
|
Country.all
|
|
228
|
-
=> #<ActiveHash::Relation:0x00007f861e0ca610 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>, #<Country:0x00007f861e059938 @attributes={:id=>2}>], @
|
|
229
|
+
=> #<ActiveHash::Relation:0x00007f861e0ca610 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>, #<Country:0x00007f861e059938 @attributes={:id=>2}>], @conditions=[..], @records_dirty=false>
|
|
229
230
|
```
|
|
230
231
|
Notice that when adding records to the collection, it will auto-increment the id for you by default. If you use string ids, it will not auto-increment the id. Available methods are:
|
|
231
232
|
```
|
|
@@ -458,6 +459,12 @@ Embedded ruby can be used in ActiveYaml using erb brackets `<% %>` and `<%= %>`
|
|
|
458
459
|
password: <%= ENV['USER_PASSWORD'] %>
|
|
459
460
|
```
|
|
460
461
|
|
|
462
|
+
This can be disabled in an initializer:
|
|
463
|
+
```ruby
|
|
464
|
+
# config/initializers/active_yaml.rb
|
|
465
|
+
ActiveYaml::Base.process_erb = false
|
|
466
|
+
```
|
|
467
|
+
|
|
461
468
|
## ActiveJSON
|
|
462
469
|
|
|
463
470
|
If you want to store your data in JSON files, just inherit from ActiveJSON and specify your path information:
|
|
@@ -617,10 +624,6 @@ To make users' lives easier, please maintain support for:
|
|
|
617
624
|
* Ruby 2.4
|
|
618
625
|
* ActiveRecord/ActiveSupport from 5.0 through edge
|
|
619
626
|
|
|
620
|
-
To that end, run specs against all rubies before committing:
|
|
621
|
-
|
|
622
|
-
wwtd
|
|
623
|
-
|
|
624
627
|
Once appraisal passes in all supported rubies, follow these steps to release a new version of active_hash:
|
|
625
628
|
|
|
626
629
|
* update the changelog with a brief summary of the changes that are included in the release
|
data/active_hash.gemspec
CHANGED
|
@@ -36,8 +36,15 @@ Gem::Specification.new do |s|
|
|
|
36
36
|
s.homepage = %q{http://github.com/active-hash/active_hash}
|
|
37
37
|
s.license = "MIT"
|
|
38
38
|
|
|
39
|
+
s.metadata = {
|
|
40
|
+
"homepage_uri" => s.homepage,
|
|
41
|
+
"changelog_uri" => "https://github.com/active-hash/active_hash/blob/master/CHANGELOG.md",
|
|
42
|
+
"source_code_uri" => s.homepage,
|
|
43
|
+
"bug_tracker_uri" => "https://github.com/active-hash/active_hash/issues",
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
s.files = [
|
|
40
|
-
"CHANGELOG",
|
|
47
|
+
"CHANGELOG.md",
|
|
41
48
|
"LICENSE",
|
|
42
49
|
"README.md",
|
|
43
50
|
"active_hash.gemspec",
|
data/lib/active_file/base.rb
CHANGED
|
@@ -2,6 +2,7 @@ module ActiveFile
|
|
|
2
2
|
|
|
3
3
|
class Base < ActiveHash::Base
|
|
4
4
|
extend ActiveFile::MultipleFiles
|
|
5
|
+
@@instance_lock = Mutex.new
|
|
5
6
|
|
|
6
7
|
class_attribute :filename, :root_path, :data_loaded, instance_reader: false, instance_writer: false
|
|
7
8
|
|
|
@@ -13,10 +14,12 @@ module ActiveFile
|
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def reload(force = false)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
@@instance_lock.synchronize do
|
|
18
|
+
return if !self.dirty && !force && self.data_loaded
|
|
19
|
+
self.data = load_file
|
|
20
|
+
mark_clean
|
|
21
|
+
self.data_loaded = true
|
|
22
|
+
end
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
def set_filename(name)
|
|
@@ -53,6 +56,10 @@ module ActiveFile
|
|
|
53
56
|
end
|
|
54
57
|
end
|
|
55
58
|
|
|
59
|
+
def all_in_process
|
|
60
|
+
return super if data_loaded
|
|
61
|
+
@records || []
|
|
62
|
+
end
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
|
@@ -13,7 +13,7 @@ module ActiveFile
|
|
|
13
13
|
loaded_files = full_paths.collect { |path| load_path(path) }
|
|
14
14
|
|
|
15
15
|
if loaded_files.all?{ |file_data| file_data.is_a?(Array) }
|
|
16
|
-
loaded_files.sum
|
|
16
|
+
loaded_files.sum([])
|
|
17
17
|
elsif loaded_files.all?{ |file_data| file_data.is_a?(Hash) }
|
|
18
18
|
loaded_files.inject({}) { |hash, file_data| hash.merge(file_data) }
|
|
19
19
|
else
|
data/lib/active_hash/base.rb
CHANGED
|
@@ -21,50 +21,8 @@ module ActiveHash
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
class Base
|
|
24
|
-
|
|
25
24
|
class_attribute :_data, :dirty, :default_attributes, :scopes
|
|
26
25
|
|
|
27
|
-
class WhereChain
|
|
28
|
-
def initialize(scope)
|
|
29
|
-
@scope = scope
|
|
30
|
-
@records = @scope.all
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def not(options)
|
|
34
|
-
return @scope if options.blank?
|
|
35
|
-
|
|
36
|
-
# use index if searching by id
|
|
37
|
-
if options.key?(:id) || options.key?("id")
|
|
38
|
-
ids = @scope.pluck(:id) - Array.wrap(options.delete(:id) || options.delete("id"))
|
|
39
|
-
candidates = ids.map { |id| @scope.find_by_id(id) }.compact
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
filtered_records = (candidates || @records || []).reject do |record|
|
|
43
|
-
options.present? && match_options?(record, options)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
ActiveHash::Relation.new(@scope.klass, filtered_records, {})
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def match_options?(record, options)
|
|
50
|
-
options.all? do |col, match|
|
|
51
|
-
if match.kind_of?(Array)
|
|
52
|
-
match.any? { |v| normalize(v) == normalize(record[col]) }
|
|
53
|
-
else
|
|
54
|
-
normalize(record[col]) == normalize(match)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
private :match_options?
|
|
60
|
-
|
|
61
|
-
def normalize(v)
|
|
62
|
-
v.respond_to?(:to_sym) ? v.to_sym : v
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private :normalize
|
|
66
|
-
end
|
|
67
|
-
|
|
68
26
|
if Object.const_defined?(:ActiveModel)
|
|
69
27
|
extend ActiveModel::Naming
|
|
70
28
|
include ActiveModel::Conversion
|
|
@@ -127,9 +85,17 @@ module ActiveHash
|
|
|
127
85
|
end
|
|
128
86
|
end
|
|
129
87
|
|
|
130
|
-
def exists?(
|
|
131
|
-
if
|
|
132
|
-
record_index[
|
|
88
|
+
def exists?(args = nil)
|
|
89
|
+
if args.respond_to?(:id)
|
|
90
|
+
record_index[args.id.to_s].present?
|
|
91
|
+
elsif args == false
|
|
92
|
+
false
|
|
93
|
+
elsif args.nil?
|
|
94
|
+
all.present?
|
|
95
|
+
elsif args.is_a?(Hash)
|
|
96
|
+
all.where(args).present?
|
|
97
|
+
else
|
|
98
|
+
all.where(id: args.to_i).present?
|
|
133
99
|
end
|
|
134
100
|
end
|
|
135
101
|
|
|
@@ -144,7 +110,7 @@ module ActiveHash
|
|
|
144
110
|
end
|
|
145
111
|
|
|
146
112
|
def next_id
|
|
147
|
-
max_record =
|
|
113
|
+
max_record = all_in_process.max { |a, b| a.id <=> b.id }
|
|
148
114
|
if max_record.nil?
|
|
149
115
|
1
|
|
150
116
|
elsif max_record.id.is_a?(Numeric)
|
|
@@ -152,6 +118,11 @@ module ActiveHash
|
|
|
152
118
|
end
|
|
153
119
|
end
|
|
154
120
|
|
|
121
|
+
def all_in_process
|
|
122
|
+
all
|
|
123
|
+
end
|
|
124
|
+
private :all_in_process
|
|
125
|
+
|
|
155
126
|
def record_index
|
|
156
127
|
@record_index ||= {}
|
|
157
128
|
end
|
|
@@ -192,7 +163,9 @@ module ActiveHash
|
|
|
192
163
|
end
|
|
193
164
|
|
|
194
165
|
def all(options = {})
|
|
195
|
-
ActiveHash::Relation.new(self, @records || []
|
|
166
|
+
relation = ActiveHash::Relation.new(self, @records || [])
|
|
167
|
+
relation = relation.where!(options[:conditions]) if options[:conditions]
|
|
168
|
+
relation
|
|
196
169
|
end
|
|
197
170
|
|
|
198
171
|
delegate :where, :find, :find_by, :find_by!, :find_by_id, :count, :pluck, :ids, :pick, :first, :last, :order, to: :all
|
|
@@ -224,7 +197,7 @@ module ActiveHash
|
|
|
224
197
|
validate_field(field_name)
|
|
225
198
|
field_names << field_name
|
|
226
199
|
|
|
227
|
-
add_default_value(field_name, options[:default]) if options
|
|
200
|
+
add_default_value(field_name, options[:default]) if options.key?(:default)
|
|
228
201
|
define_getter_method(field_name, options[:default])
|
|
229
202
|
define_setter_method(field_name)
|
|
230
203
|
define_interrogator_method(field_name)
|
|
@@ -482,7 +455,11 @@ module ActiveHash
|
|
|
482
455
|
when new_record?
|
|
483
456
|
"#{self.class.cache_key}/new"
|
|
484
457
|
when timestamp = self[:updated_at]
|
|
485
|
-
|
|
458
|
+
if ActiveSupport::VERSION::MAJOR < 7
|
|
459
|
+
"#{self.class.cache_key}/#{id}-#{timestamp.to_s(:number)}"
|
|
460
|
+
else
|
|
461
|
+
"#{self.class.cache_key}/#{id}-#{timestamp.to_fs(:number)}"
|
|
462
|
+
end
|
|
486
463
|
else
|
|
487
464
|
"#{self.class.cache_key}/#{id}"
|
|
488
465
|
end
|