active_hash 3.1.1 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +366 -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 +107 -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 +27 -14
- data/lib/associations/reflection_extensions.rb +25 -0
- metadata +15 -8
- 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: 993ef228f8c89c89dc8f18087b7ed609dc575e3e6031abd82d18673322d42d0d
|
4
|
+
data.tar.gz: 8871a88db27cc363de8d813d98a1d3f354d83c0cc76c0f0a03fb093e5d8a5226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4c19f95913358f7a7c46e76871bd3845e7e61d82515e725933f162d5735b5fae5f52aeb376b7a61ae9459640692b335f11312b2ae00d43ba353b55cd3358638
|
7
|
+
data.tar.gz: 07a92392da1c142801aa2f5ed60ffa0b1e7ee8a8638096b7f4dd707d4d98c767082e95cfbc3cebce0da7e189a71246bb7d1a349a730d11cf8e146171cea060e2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,366 @@
|
|
1
|
+
# active_hash Changelog
|
2
|
+
|
3
|
+
## Version [3.2.1] - <sub><sup>2023-08-31</sup></sub>
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Improve `pp` output for `ActiveHash::Relation`. [#288](https://github.com/active-hash/active_hash/pull/288) @flavorjones
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- Fix relation matching when attribute name collides with a method. [#281](https://github.com/active-hash/active_hash/pull/281) @flavorjones
|
12
|
+
- Fix association reflection in applications that don't use ActiveHash::Associations. [#286](https://github.com/active-hash/active_hash/pull/286) @iberianpig
|
13
|
+
- Fix `ActiveHash::Relation#method_missing` and `#respond_to_missing?` without scopes. [#278](https://github.com/active-hash/active_hash/pull/278) @julianrubisch
|
14
|
+
|
15
|
+
|
16
|
+
## Version [3.2.0] - <sub><sup>2023-05-06</sup></sub>
|
17
|
+
|
18
|
+
- Add Ruby 3.2 to the CI matrix [#275](https://github.com/active-hash/active_hash/pull/275) @petergoldstein
|
19
|
+
- Handle default value of `false` [#274](https://github.com/active-hash/active_hash/pull/274) @ihollander
|
20
|
+
- Run CI only one time per commit [#273](https://github.com/active-hash/active_hash/pull/273) @flavorjones
|
21
|
+
- Rails 7 support [#272](https://github.com/active-hash/active_hash/pull/272) @flavorjones
|
22
|
+
- Avoid interfere with AR's belongs_to arguments. [#270](https://github.com/active-hash/active_hash/pull/270) @koyo-miyamura
|
23
|
+
- Fix broken #pluck method with 3+ attrs specified [#269](https://github.com/active-hash/active_hash/pull/269) @h6ah4i
|
24
|
+
- Fix relations for Rails 7 support, and not modifying conditions [#268](https://github.com/active-hash/active_hash/pull/268) @pfeiffer
|
25
|
+
- docs: Remove the string 'F' [#264](https://github.com/active-hash/active_hash/pull/264) @tbotaq
|
26
|
+
- Show example using regex in where query [#263](https://github.com/active-hash/active_hash/pull/263) @scottharvey
|
27
|
+
- Improve performance of exists? [#262](https://github.com/active-hash/active_hash/pull/262) @ise-tang
|
28
|
+
- Remove redundant ActiveRecord version check [#260](https://github.com/active-hash/active_hash/pull/260) @yujideveloper
|
29
|
+
- Fix deprecation warnings [#259](https://github.com/active-hash/active_hash/pull/259) @yujideveloper
|
30
|
+
- Fix rspec config when SKIP_ACTIVE_RECORD enabled [#258](https://github.com/active-hash/active_hash/pull/258) @yujideveloper
|
31
|
+
- isolate tests with temporary classes [#256](https://github.com/active-hash/active_hash/pull/256) @machisuke
|
32
|
+
- Avoid ActiveRecordExtensions affects AR's belongs_to method. [#255](https://github.com/active-hash/active_hash/pull/255) @machisuke
|
33
|
+
- add option to disable erb parsing [#202](https://github.com/active-hash/active_hash/pull/202) @reedlaw
|
34
|
+
- add collection singular ids for associations [#237](https://github.com/active-hash/active_hash/pull/237) @1160054
|
35
|
+
- Fix the thread-safe spec for the updated cities fixture @adampal
|
36
|
+
- Add thread-safety to ActiveFile [#229](https://github.com/active-hash/active_hash/pull/229) @dmitriy-kiriyenko
|
37
|
+
|
38
|
+
## Version [3.1.1] - <sub><sup>2022-07-14</sup></sub>
|
39
|
+
|
40
|
+
- Make scopes chainable [#248](https://github.com/active-hash/active_hash/pull/248) @andreynering
|
41
|
+
- Set default key attributes [#251](https://github.com/active-hash/active_hash/pull/251/commits/68a0a121d110ac83f4bbf0024f027714fd24debf) @adampal
|
42
|
+
- Migrate from Travis to GitHub Actions for CI @kbrock
|
43
|
+
- Add primary_key support for has_one [#218](https://github.com/active-hash/active_hash/pull/218) @yujideveloper
|
44
|
+
- Return a chainable relation when using .not [#205](https://github.com/active-hash/active_hash/pull/205) @pfeiffer
|
45
|
+
- Correct fields with YAML aliases in array style [#226](https://github.com/active-hash/active_hash/pull/226) @stomk
|
46
|
+
- Add ActiveHash::Relation#size method for compatibily [#227](https://github.com/active-hash/active_hash/pull/227) @sluceno
|
47
|
+
- Implement ActiveRecord::RecordNotFound interface [#207](https://github.com/active-hash/active_hash/pull/207) @ChrisBr
|
48
|
+
- Fix find_by_id with filter chain [#210](https://github.com/active-hash/active_hash/pull/210) @ChrisBr
|
49
|
+
- Suppress Ruby 2.7 kwargs warnings [#206](https://github.com/active-hash/active_hash/pull/206) @yhirano55
|
50
|
+
- Call reload if @records is not defined [#208](https://github.com/active-hash/active_hash/pull/208) @jonmagic
|
51
|
+
- Switch to rspec3 (and update the Gemfile) [#209](https://github.com/active-hash/active_hash/pull/209) @djberg96
|
52
|
+
- Implement filter by RegEx [#211](https://github.com/active-hash/active_hash/pull/211) @ChrisBr
|
53
|
+
- Supports .pick method [#195](https://github.com/active-hash/active_hash/pull/195/files) @yhirano55
|
54
|
+
- Lots of other small performance improvements, documentation and testing. Thanks to everyone who contributed!
|
55
|
+
|
56
|
+
## Version [3.1.0] - <sub><sup>2020-01-15</sup></sub>
|
57
|
+
|
58
|
+
- Add ActiveHash::Base.order method inspired by ActiveRecord [#177](https://github.com/active-hash/active_hash/pull/177)
|
59
|
+
- Add #to_ary to ActiveHash::Relation [#182](https://github.com/active-hash/active_hash/pull/182)
|
60
|
+
- 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)
|
61
|
+
- Delegate :sample to `records` [#189](https://github.com/active-hash/active_hash/pull/189)
|
62
|
+
|
63
|
+
## Version [3.0.0] - <sub><sup>2019-09-28</sup></sub>
|
64
|
+
|
65
|
+
- Make #where chainable [#178](https://github.com/active-hash/active_hash/pull/178)
|
66
|
+
|
67
|
+
## Version [2.3.0] - <sub><sup>2019-09-28</sup></sub>
|
68
|
+
|
69
|
+
- Add ::scope method (inspired by ActiveRecord) [#173](https://github.com/active-hash/active_hash/pull/173)
|
70
|
+
- Let `.find(nil)` raise ActiveHash::RecordNotFound (inspired by ActiveRecord) [#174](https://github.com/active-hash/active_hash/pull/174)
|
71
|
+
- `where` clause now works with range argument [#175](https://github.com/active-hash/active_hash/pull/175)
|
72
|
+
|
73
|
+
## Version [2.2.1] - <sub><sup>2019-03-06</sup></sub>
|
74
|
+
|
75
|
+
- Allow empty YAML [#171](https://github.com/active-hash/active_hash/pull/171) Thanks, @ppworks
|
76
|
+
|
77
|
+
## Version [2.2.0] - <sub><sup>2018-11-22</sup></sub>
|
78
|
+
|
79
|
+
- Support pluck method [#164](https://github.com/active-hash/active_hash/pull/164) Thanks, @ihatov08
|
80
|
+
- Support where.not method [#167](https://github.com/active-hash/active_hash/pull/167) Thanks, @DialBird
|
81
|
+
|
82
|
+
## Version [2.1.0] - <sub><sup>2018-04-05</sup></sub>
|
83
|
+
|
84
|
+
- Allow to use ERB (embedded ruby) in yml files [#160](https://github.com/active-hash/active_hash/pull/160) Thanks, @UgoMare
|
85
|
+
- Add `ActiveHash::Base.polymorphic_name` [#162](https://github.com/active-hash/active_hash/pull/162)
|
86
|
+
- 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
|
87
|
+
|
88
|
+
## Version [2.0.0] - <sub><sup>2018-02-27</sup></sub>
|
89
|
+
|
90
|
+
- Drop old Ruby and Rails support [#157](https://github.com/active-hash/active_hash/pull/157)
|
91
|
+
- Don't generate instance accessors for class attributes [#136](https://github.com/active-hash/active_hash/pull/136) Thanks, @rainhead
|
92
|
+
|
93
|
+
## Version [1.5.3] - <sub><sup>2017-06-14</sup></sub>
|
94
|
+
|
95
|
+
- Support symbol values in where and find_by [#156](https://github.com/active-hash/active_hash/pull/156) Thanks, @south37
|
96
|
+
|
97
|
+
## Version [1.5.2] - <sub><sup>2017-06-14</sup></sub>
|
98
|
+
|
99
|
+
- Fix find_by when passed an invalid id [#152](https://github.com/active-hash/active_hash/pull/152) Thanks, @davidstosik
|
100
|
+
|
101
|
+
## Version [1.5.1] - <sub><sup>2017-04-20</sup></sub>
|
102
|
+
|
103
|
+
- Fix a bug on `.where` [#147](https://github.com/active-hash/active_hash/pull/147)
|
104
|
+
|
105
|
+
## Version [1.5.0] - <sub><sup>2017-03-24</sup></sub>
|
106
|
+
|
107
|
+
- add support for `.find_by!`(@syguer)
|
108
|
+
|
109
|
+
## Version [1.4.1] - <sub><sup>2015-09-13</sup></sub>
|
110
|
+
|
111
|
+
- fix bug where `#attributes` didn't contain default values [#107](https://github.com/active-hash/active_hash/pull/107)
|
112
|
+
- add support for `.find_by` and `#_read_attribute`. Thanks, @andrewfader
|
113
|
+
|
114
|
+
## Version [1.4.0] - <sub><sup>2014-09-03</sup></sub>
|
115
|
+
|
116
|
+
- support Rails 4.2 @agraves, @al2o3cr
|
117
|
+
|
118
|
+
## Version [1.3.0] - <sub><sup>2014-02-18</sup></sub>
|
119
|
+
|
120
|
+
- fix bug where including ActiveHash associations would make `belongs_to :imageable, polymorphic: true` blow up
|
121
|
+
- fixed several bugs that prevented active hash from being used without active record / active model
|
122
|
+
- add support for splitting up data sources into multiple files @rheaton
|
123
|
+
- add support for storing data in json files @rheaton
|
124
|
+
|
125
|
+
## Version [1.2.3] - <sub><sup>2013-11-29</sup></sub>
|
126
|
+
|
127
|
+
- fix bug where active hash would call `.all` on models when setting has_many @grosser
|
128
|
+
|
129
|
+
## Version [1.2.2] - <sub><sup>2013-11-05</sup></sub>
|
130
|
+
|
131
|
+
- fix bug in gemspec that made it impossible to use w/ Rails 4
|
132
|
+
|
133
|
+
## Version [1.2.1] - <sub><sup>2013-10-24</sup></sub>
|
134
|
+
|
135
|
+
- fixed nasty bug in belongs_to that would prevent users from passing procs @freebird0221
|
136
|
+
- fixed bug where passing in a separate class name to belongs_to_active_hash would raise an exception @mauriciopasquier
|
137
|
+
|
138
|
+
## Version [1.2.0] - <sub><sup>2013-10-01</sup></sub>
|
139
|
+
|
140
|
+
- belongs_to is back!
|
141
|
+
- added support for primary key options for belongs_to @tomtaylor
|
142
|
+
|
143
|
+
## Version [1.0.2] - <sub><sup>2013-09-09</sup></sub>
|
144
|
+
|
145
|
+
- `where(nil)` returns all results, like ActiveRecord @kugaevsky
|
146
|
+
|
147
|
+
## Version [1.0.1] - <sub><sup>2013-07-15</sup></sub>
|
148
|
+
|
149
|
+
- Travis CI for ActiveHash + Ruby 2, 1.8.7, Rubinius and JRuby support @mattheworiordan
|
150
|
+
- no longer need to call .all before executing `find_by_*` or `where` methods @mattheworiordan
|
151
|
+
|
152
|
+
## Version [1.0.0] - <sub><sup>2013-06-24</sup></sub>
|
153
|
+
|
154
|
+
- save is a no-op on existing records, instead of raising an error (issue #63)
|
155
|
+
|
156
|
+
## Version [0.10.0] - <sub><sup>2013-06-24</sup></sub>
|
157
|
+
|
158
|
+
- added ActiveYaml::Aliases module so you can DRY up your repetitive yaml @brett-richardson
|
159
|
+
|
160
|
+
## Version [0.9.14] - <sub><sup>2013-05-23</sup></sub>
|
161
|
+
|
162
|
+
- enum_accessor can now take multiple field names when generating the constant
|
163
|
+
- temporarily disabled rails edge specs since there's an appraisal issue with minitest
|
164
|
+
|
165
|
+
## Version [0.9.13] <sub><sup>2013-01-22</sup></sub>
|
166
|
+
- Fix find_by_id and find method returning nil unless .all called in ActiveYaml @mattheworiordan
|
167
|
+
|
168
|
+
## Version [0.9.12] <sub><sup>2012-07-25</sup></sub>
|
169
|
+
- Make find_by_id lookups faster by indexing records by id @desmondmonster
|
170
|
+
|
171
|
+
## Version [0.9.11] <sub><sup>2012-07-16</sup></sub>
|
172
|
+
- Validate IDs are unique by caching them in a set @desmondmonster
|
173
|
+
|
174
|
+
## Version [0.9.10] <sub><sup>2012-04-14</sup></sub>
|
175
|
+
- Support for has_one associations @kbrock
|
176
|
+
|
177
|
+
## Version [0.9.9] <sub><sup>2012-04-05</sup></sub>
|
178
|
+
|
179
|
+
- Allow gems like simple_form to read metadata about belongs_to associations that point to active hash objects @kbrock
|
180
|
+
- Move specs to appraisal @flavorjones
|
181
|
+
|
182
|
+
## Version [0.9.8] - <sub><sup>2012-01-18</sup></sub>
|
183
|
+
|
184
|
+
- Make ActiveHash.find with array raise an exception when record cannot be found @mocoso
|
185
|
+
|
186
|
+
## Version [0.9.7] - <sub><sup>2011-09-18</sup></sub>
|
187
|
+
|
188
|
+
- Fixing the setting of a `belongs_to_active_hash` association by association (not id).
|
189
|
+
|
190
|
+
## Version [0.9.6] - <sub><sup>2011-08-31</sup></sub>
|
191
|
+
- added a module which adds a .belongs_to_active_hash method to ActiveRecord, since it was broken for Rails 3.1 @felixclack
|
192
|
+
|
193
|
+
## Version [0.9.5] - <sub><sup>2011-06-07</sup></sub>
|
194
|
+
- fixed bug where .find would not work if you defined your ids as strings
|
195
|
+
|
196
|
+
## Version [0.9.4] - <sub><sup>2011-06-05</sup></sub>
|
197
|
+
- fixed deprecation warnings for class_inheritable_accessor @scudco
|
198
|
+
- added basic compatibility with the `where` method from Arel @rgarver
|
199
|
+
|
200
|
+
## Version [0.9.3] - <sub><sup>2011-04-19</sup></sub>
|
201
|
+
- better dependency management and compatibility with ActiveSupport 2.x @vandrijevik
|
202
|
+
|
203
|
+
## Version [0.9.2] - <sub><sup>2011-01-22</sup></sub>
|
204
|
+
- improved method_missing errors for dynamic finders
|
205
|
+
- prevent users from trying to overwrite :attributes [#33](https://github.com/active-hash/active_hash/issues/33)
|
206
|
+
|
207
|
+
## Version [0.9.1] <sub><sup>2010-12-08</sup></sub>
|
208
|
+
- ruby 1.9.2 compatibility
|
209
|
+
|
210
|
+
## Version [0.9.0] <sub><sup>2010-12-06</sup></sub>
|
211
|
+
- added dependency on ActiveModel
|
212
|
+
- add persisted? method to ActiveHash::Base
|
213
|
+
- ActiveHash::Base#save takes \*args to be compatible with ActiveModel
|
214
|
+
- ActiveHash::Base#to_param returns nil if the object hasn't been saved
|
215
|
+
|
216
|
+
## Version [0.8.7] <sub><sup>2010-11-09</sup></sub>
|
217
|
+
- Use Ruby's definition of "word character" (numbers, underscores) when forming ActiveHash::Enum constants @tstuart
|
218
|
+
|
219
|
+
## Version [0.8.6] <sub><sup>2010-11-07</sup></sub>
|
220
|
+
- Get ActiveHash::Associations to return a scope for has_many active record relationships @mocoso
|
221
|
+
|
222
|
+
## Version [0.8.5] <sub><sup>2010-10-20</sup></sub>
|
223
|
+
- Allow find_by_* methods to accept an options hash, so rails associations don't blow up
|
224
|
+
|
225
|
+
## Version [0.8.4] <sub><sup>2010-10-07</sup></sub>
|
226
|
+
- Add conditions to ActiveHash#all (Ryan Garver)
|
227
|
+
- Add #cache_key to ActiveHash::Base (Tom Stuart)
|
228
|
+
- Add banged dynamic finder support to ActiveHash::Base (Tom Stuart)
|
229
|
+
|
230
|
+
## Version [0.8.3] <sub><sup>2010-09-16</sup></sub>
|
231
|
+
- Enum format now uses underscores instead of removing all characters
|
232
|
+
- Removed test dependency on acts_as_fu
|
233
|
+
|
234
|
+
## Version [0.8.2] <sub><sup>2010-05-26</sup></sub>
|
235
|
+
- Silence metaclass deprecation warnings in active support 2.3.8
|
236
|
+
|
237
|
+
## Version [0.8.1] <sub><sup>2010-05-04</sup></sub>
|
238
|
+
- 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)
|
239
|
+
|
240
|
+
## Version [0.8.0] <sub><sup>2010-04-25</sup></sub>
|
241
|
+
- When ActiveRecord model belongs_to an ActiveHash and the associated id is nil, returns nil instead of raising RecordNotFound (Jeremy Weiskotten)
|
242
|
+
- Merged Nakajima's "add" alias for "create" - gotta save those ASCII characters :)
|
243
|
+
|
244
|
+
## Version [0.7.9] <sub><sup>2010-03-01</sup></sub>
|
245
|
+
- Removed "extend"-related deprecations - they didn't play well with rails class loading
|
246
|
+
|
247
|
+
## Version [0.7.8] <sub><sup>2010-01-18</sup></sub>
|
248
|
+
- Added stub for #destroyed? method, since Rails associations now depend on it
|
249
|
+
|
250
|
+
## Version [0.7.7] <sub><sup>2009-12-19</sup></sub>
|
251
|
+
- Deprecated include ActiveHash::Associations in favor of extend ActiveHash::Associations
|
252
|
+
|
253
|
+
## Version [0.7.6] <sub><sup>2009-12-19</sup></sub>
|
254
|
+
- Added ActiveHash::Enum (John Pignata)
|
255
|
+
- Fixed bug where you can't set nil to an association
|
256
|
+
- Calling #belongs_to now creates the underlying field if it's not already there (belongs_to :city will create the :city_id field)
|
257
|
+
|
258
|
+
## Version [0.7.5] <sub><sup>2009-12-10</sup></sub>
|
259
|
+
- Fixed a bug where belongs_to associations would raise an error instead of returning nil when the parent object didn't exist.
|
260
|
+
- Added #[] and #[]= accessors for more ActiveRecord-esque-ness. (Pat Nakajima & Dave Yeu)
|
261
|
+
|
262
|
+
## Version [0.7.4] <sub><sup>2009-12-01</sup></sub>
|
263
|
+
- Add marked_for_destruction? to be compatible with nested attributes (Brandon Keene)
|
264
|
+
- Added second parameter to respond_to? and cleaned up specs (Brian Takita)
|
265
|
+
- Find with an id that does not exist now raises a RecordNotFound exception to mimic ActiveRecord (Pat Nakajima)
|
266
|
+
|
267
|
+
## Version [0.7.3] <sub><sup>2009-10-22</sup></sub>
|
268
|
+
- added setters to ActiveHash::Base for all fields
|
269
|
+
- instantiating an ActiveHash object with a hash calls the setter methods on the object
|
270
|
+
- boolean default values now work
|
271
|
+
|
272
|
+
## Version [0.7.2] <sub><sup>2009-10-21</sup></sub>
|
273
|
+
- Removed auto-reloading of files based on mtime - maybe it will come back later
|
274
|
+
- Made ActiveFile::Base.all a bit more sane
|
275
|
+
|
276
|
+
## Version 0.7.1 <sub><sup>2009-10-13</sup></sub>
|
277
|
+
- added ActiveHash::Base.has_many, which works with ActiveRecord or ActiveHash classes @baldwindavid
|
278
|
+
- added ActiveHash::Base.belongs_to, which works with ActiveRecord or ActiveHash classes @baldwindavid
|
279
|
+
- added .delete_all method that clears the in-memory array
|
280
|
+
- added support for Hash-style yaml (think, Rails fixtures)
|
281
|
+
- added setter for parent object on belongs_to ( `city = City.new; city.state = State.first; city.state_id == State.first.id` )
|
282
|
+
|
283
|
+
## Version [0.7.0] <sub><sup>2009-10-12</sup></sub>
|
284
|
+
- auto-assign fields after calling data= instead of after calling .all
|
285
|
+
- remove require 'rubygems', so folks with non-gem setups can still use AH
|
286
|
+
- added more specific activesupport dependency to ensure that metaclass is available
|
287
|
+
- AH no longer calls to_i on ids. If you pass in a string as an id, you'll get a string back
|
288
|
+
- 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
|
289
|
+
- You can now use ActiveHash models as the parents of polymorphic belongs_to associations
|
290
|
+
- save, save!, create and create! now add items to the in-memory collection, and naively adds autoincrementing id
|
291
|
+
- new_record? returns false if the record is part of the collection
|
292
|
+
- ActiveHash now works with Fixjour!
|
293
|
+
|
294
|
+
## Version [0.6.1] <sub><sup>2009-08-19</sup></sub>
|
295
|
+
- Added custom finders for multiple fields, such as .find_all_by_name_and_age
|
296
|
+
|
297
|
+
## Version 0.5.0 <sub><sup>2009-07-23</sup></sub>
|
298
|
+
- Added support for auto-defining methods based on hash keys in ActiveHash::Base
|
299
|
+
- Changed the :field and :fields API so that they don't overwrite existing methods (useful when ActiveHash auto-defines methods)
|
300
|
+
- Fixed a bug where ActiveFile incorrectly set the root_path to be the path in the gem directory, not the current working directory
|
301
|
+
|
302
|
+
## Version 0.4.0 <sub><sup>2009-07-24</sup></sub>
|
303
|
+
- ActiveFile no longer reloads files by default
|
304
|
+
- Added ActiveFile.reload_active_file= so you can cause ActiveFile to reload
|
305
|
+
- Setting data to nil correctly causes .all to return an empty array
|
306
|
+
- Added reload(force) method, so that you can force a reload from files in ActiveFile, useful for tests
|
307
|
+
|
308
|
+
[HEAD]: https://github.com/active-hash/active_hash/compare/v4.3.0...HEAD
|
309
|
+
[4.3.0]: https://github.com/active-hash/active_hash/compare/v3.2.0...v4.3.0
|
310
|
+
[4.2.0]: https://github.com/active-hash/active_hash/compare/v3.1.1...v4.2.0
|
311
|
+
[3.1.1]: https://github.com/active-hash/active_hash/compare/v3.1.0...v3.1.1
|
312
|
+
[3.1.0]: https://github.com/active-hash/active_hash/compare/v3.0.0...v3.1.0
|
313
|
+
[3.0.0]: https://github.com/active-hash/active_hash/compare/v2.3.0...v3.0.0
|
314
|
+
[2.3.0]: https://github.com/active-hash/active_hash/compare/v2.2.1...v2.3.0
|
315
|
+
[2.2.1]: https://github.com/active-hash/active_hash/compare/v2.2.0...v2.2.1
|
316
|
+
[2.2.0]: https://github.com/active-hash/active_hash/compare/v2.1.0...v2.2.0
|
317
|
+
[2.1.0]: https://github.com/active-hash/active_hash/compare/v2.0.0...v2.1.0
|
318
|
+
[2.0.0]: https://github.com/active-hash/active_hash/compare/v1.5.3...v2.0.0
|
319
|
+
[1.5.3]: https://github.com/active-hash/active_hash/compare/v1.5.2...v1.5.3
|
320
|
+
[1.5.2]: https://github.com/active-hash/active_hash/compare/v1.5.1...v1.5.2
|
321
|
+
[1.5.1]: https://github.com/active-hash/active_hash/compare/v1.5.0...v1.5.1
|
322
|
+
[1.5.0]: https://github.com/active-hash/active_hash/compare/v1.4.1...v1.5.0
|
323
|
+
[1.4.1]: https://github.com/active-hash/active_hash/compare/v1.4.0...v1.4.1
|
324
|
+
[1.4.0]: https://github.com/active-hash/active_hash/compare/v1.3.0...v1.4.0
|
325
|
+
[1.3.0]: https://github.com/active-hash/active_hash/compare/v1.2.3...v1.3.0
|
326
|
+
[1.2.3]: https://github.com/active-hash/active_hash/compare/v1.2.2...v1.2.3
|
327
|
+
[1.2.2]: https://github.com/active-hash/active_hash/compare/v1.2.1...v1.2.2
|
328
|
+
[1.2.1]: https://github.com/active-hash/active_hash/compare/v1.2.0...v1.2.1
|
329
|
+
[1.2.0]: https://github.com/active-hash/active_hash/compare/v1.0.2...v1.2.0
|
330
|
+
[1.0.2]: https://github.com/active-hash/active_hash/compare/v1.0.1...v1.0.2
|
331
|
+
[1.0.1]: https://github.com/active-hash/active_hash/compare/v1.0.0...v1.0.1
|
332
|
+
[1.0.0]: https://github.com/active-hash/active_hash/compare/v0.10.0...v1.0.0
|
333
|
+
[0.10.0]: https://github.com/active-hash/active_hash/compare/v0.9.14...v0.10.0
|
334
|
+
[0.9.14]: https://github.com/active-hash/active_hash/compare/v0.9.13...v0.9.14
|
335
|
+
[0.9.13]: https://github.com/active-hash/active_hash/compare/v0.9.12...v0.9.13
|
336
|
+
[0.9.12]: https://github.com/active-hash/active_hash/compare/v0.9.11...v0.9.12
|
337
|
+
[0.9.11]: https://github.com/active-hash/active_hash/compare/v0.9.10...v0.9.11
|
338
|
+
[0.9.10]: https://github.com/active-hash/active_hash/compare/v0.9.9...v0.9.10
|
339
|
+
[0.9.9]: https://github.com/active-hash/active_hash/compare/v0.9.8...v0.9.9
|
340
|
+
[0.9.8]: https://github.com/active-hash/active_hash/compare/v0.9.7...v0.9.8
|
341
|
+
[0.9.7]: https://github.com/active-hash/active_hash/compare/v0.9.6...v0.9.7
|
342
|
+
[0.9.6]: https://github.com/active-hash/active_hash/compare/v0.9.5...v0.9.6
|
343
|
+
[0.9.5]: https://github.com/active-hash/active_hash/compare/v0.9.4...v0.9.5
|
344
|
+
[0.9.4]: https://github.com/active-hash/active_hash/compare/v0.9.3...v0.9.4
|
345
|
+
[0.9.3]: https://github.com/active-hash/active_hash/compare/v0.9.2...v0.9.3
|
346
|
+
[0.9.2]: https://github.com/active-hash/active_hash/compare/v0.9.1...v0.9.2
|
347
|
+
[0.9.1]: https://github.com/active-hash/active_hash/compare/v0.9.0...v0.9.1
|
348
|
+
[0.9.0]: https://github.com/active-hash/active_hash/compare/v0.8.7...v0.9.0
|
349
|
+
[0.8.7]: https://github.com/active-hash/active_hash/compare/v0.8.6...v0.8.7
|
350
|
+
[0.8.6]: https://github.com/active-hash/active_hash/compare/v0.8.5...v0.8.6
|
351
|
+
[0.8.5]: https://github.com/active-hash/active_hash/compare/v0.8.4...v0.8.5
|
352
|
+
[0.8.4]: https://github.com/active-hash/active_hash/compare/v0.8.3...v0.8.4
|
353
|
+
[0.8.3]: https://github.com/active-hash/active_hash/compare/v0.8.2...v0.8.3
|
354
|
+
[0.8.2]: https://github.com/active-hash/active_hash/compare/v0.8.1...v0.8.2
|
355
|
+
[0.8.1]: https://github.com/active-hash/active_hash/compare/v0.8.0...v0.8.1
|
356
|
+
[0.8.0]: https://github.com/active-hash/active_hash/compare/v0.7.9...v0.8.0
|
357
|
+
[0.7.9]: https://github.com/active-hash/active_hash/compare/v0.7.8...v0.7.9
|
358
|
+
[0.7.8]: https://github.com/active-hash/active_hash/compare/v0.7.7...v0.7.8
|
359
|
+
[0.7.7]: https://github.com/active-hash/active_hash/compare/v0.7.6...v0.7.7
|
360
|
+
[0.7.6]: https://github.com/active-hash/active_hash/compare/v0.7.5...v0.7.6
|
361
|
+
[0.7.5]: https://github.com/active-hash/active_hash/compare/v0.7.4...v0.7.5
|
362
|
+
[0.7.4]: https://github.com/active-hash/active_hash/compare/v0.7.3...v0.7.4
|
363
|
+
[0.7.3]: https://github.com/active-hash/active_hash/compare/v0.7.2...v0.7.3
|
364
|
+
[0.7.2]: https://github.com/active-hash/active_hash/compare/v0.7.0...v0.7.2
|
365
|
+
[0.7.0]: https://github.com/active-hash/active_hash/compare/v0.6.1...v0.7.0
|
366
|
+
[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
|