active_hash 3.0.0 → 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 +62 -19
- data/active_hash.gemspec +9 -2
- data/lib/active_file/base.rb +13 -6
- data/lib/active_file/hash_and_array_files.rb +1 -1
- data/lib/active_hash/base.rb +42 -55
- data/lib/active_hash/condition.rb +44 -0
- data/lib/active_hash/conditions.rb +21 -0
- data/lib/active_hash/relation.rb +175 -72
- data/lib/active_hash/version.rb +1 -1
- data/lib/active_hash.rb +2 -0
- data/lib/active_yaml/aliases.rb +11 -6
- data/lib/active_yaml/base.rb +16 -2
- data/lib/associations/associations.rb +30 -19
- data/lib/associations/reflection_extensions.rb +25 -0
- metadata +13 -7
- data/CHANGELOG +0 -219
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
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveHash
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/active-hash/active_hash/actions/workflows/ruby.yml/badge.svg)](https://github.com/active-hash/active_hash/actions/workflows/ruby.yml)
|
4
4
|
|
5
5
|
ActiveHash is a simple base class that allows you to use a ruby hash as a readonly datasource for an ActiveRecord-like model.
|
6
6
|
|
@@ -17,7 +17,7 @@ ActiveHash also ships with:
|
|
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
|
-
If it breaks your application, please report us on [issues](https://github.com/
|
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..
|
21
21
|
|
22
22
|
```ruby
|
23
23
|
gem 'active_hash', '~> 2.3.0'
|
@@ -131,7 +131,7 @@ NOTE: auto-defined fields will _not_ override fields you've defined, either on t
|
|
131
131
|
If some of your hash values contain nil, and you want to provide a default, you can specify defaults with the :field method:
|
132
132
|
```ruby
|
133
133
|
class Country < ActiveHash::Base
|
134
|
-
field
|
134
|
+
field :is_axis_of_evil, :default => false
|
135
135
|
end
|
136
136
|
```
|
137
137
|
## Defining Data
|
@@ -164,11 +164,14 @@ Country.find 1 # => returns the first country object with that i
|
|
164
164
|
Country.find [1,2] # => returns all Country objects with ids in the array
|
165
165
|
Country.find :all # => same as .all
|
166
166
|
Country.find :all, args # => the second argument is totally ignored, but allows it to play nicely with AR
|
167
|
+
Country.find { |country| country.name.start_with?('U') } # => returns the first country for which the block evaluates to true
|
167
168
|
Country.find_by_id 1 # => find the first object that matches the id
|
168
169
|
Country.find_by(name: 'US') # => returns the first country object with specified argument
|
169
170
|
Country.find_by!(name: 'US') # => same as find_by, but raise exception when not found
|
170
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/
|
171
173
|
Country.where.not(name: 'US') # => returns all records without name: 'US'
|
174
|
+
Country.order(name: :desc) # => returns all records ordered by name attribute in DESC order
|
172
175
|
```
|
173
176
|
It also gives you a few dynamic finder methods. For example, if you defined :name as a field, you'd get:
|
174
177
|
```ruby
|
@@ -206,16 +209,24 @@ Country#name= # => sets the name
|
|
206
209
|
```
|
207
210
|
## Saving in-memory records
|
208
211
|
|
209
|
-
The ActiveHash::Base.all method functions like an in-memory data store.
|
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:
|
210
213
|
```ruby
|
211
|
-
Country.all
|
214
|
+
Country.all
|
215
|
+
=> #<ActiveHash::Relation:0x00007f861e043bb0 @klass=Country, @all_records=[], @conditions=[..], @records_dirty=false>
|
212
216
|
Country.create
|
213
|
-
|
217
|
+
=> #<Country:0x00007f861b7abce8 @attributes={:id=>1}>
|
218
|
+
Country.all
|
219
|
+
=> #<ActiveHash::Relation:0x00007f861b7b3628 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>], @conditions=[..], @records_dirty=false>
|
214
220
|
country = Country.new
|
215
|
-
|
221
|
+
=> #<Country:0x00007f861e059938 @attributes={}>
|
222
|
+
country.new_record?
|
223
|
+
=> true
|
216
224
|
country.save
|
217
|
-
|
218
|
-
|
225
|
+
=> true
|
226
|
+
country.new_record?
|
227
|
+
# => false
|
228
|
+
Country.all
|
229
|
+
=> #<ActiveHash::Relation:0x00007f861e0ca610 @klass=Country, @all_records=[#<Country:0x00007f861b7abce8 @attributes={:id=>1}>, #<Country:0x00007f861e059938 @attributes={:id=>2}>], @conditions=[..], @records_dirty=false>
|
219
230
|
```
|
220
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:
|
221
232
|
```
|
@@ -339,7 +350,7 @@ end
|
|
339
350
|
The above example will look for the file "/u/data/sample.yml".
|
340
351
|
|
341
352
|
Since ActiveYaml just creates a hash from the YAML file, you will have all fields specified in YAML auto-defined for you. You can format your YAML as an array, or as a hash:
|
342
|
-
```
|
353
|
+
```yaml
|
343
354
|
# array style
|
344
355
|
- id: 1
|
345
356
|
name: US
|
@@ -359,6 +370,35 @@ mexico:
|
|
359
370
|
id: 3
|
360
371
|
name: Mexico
|
361
372
|
```
|
373
|
+
|
374
|
+
### Automatic Key Attribute
|
375
|
+
|
376
|
+
When using the hash format for your YAML file, ActiveYaml will automatically add a `key` attribute with the name of the object. You can overwrite this by setting the key attribute in the YAML file.
|
377
|
+
For example:
|
378
|
+
```
|
379
|
+
au:
|
380
|
+
id: 1
|
381
|
+
name: Australia
|
382
|
+
```
|
383
|
+
|
384
|
+
When you access the object you can do `Country.find(1).key => 'au'`. Or `Country.find_by_key('au')`
|
385
|
+
|
386
|
+
If you want a different key on only some objects you can mix and match:
|
387
|
+
|
388
|
+
```
|
389
|
+
au:
|
390
|
+
id: 1
|
391
|
+
key: aus
|
392
|
+
name: Australia
|
393
|
+
nz:
|
394
|
+
id: 2
|
395
|
+
name: New Zealand
|
396
|
+
```
|
397
|
+
|
398
|
+
`Country.find(1).key => 'aus'`
|
399
|
+
|
400
|
+
`Country.find(2).key => 'nz'`
|
401
|
+
|
362
402
|
### Multiple files per model
|
363
403
|
|
364
404
|
You can use multiple files to store your data. You will have to choose between hash or array style as you cannot use both for one model.
|
@@ -372,7 +412,7 @@ end
|
|
372
412
|
|
373
413
|
Aliases can be used in ActiveYaml using either array or hash style by including `ActiveYaml::Aliases`.
|
374
414
|
With that module included, keys beginning with a '/' character can be safely added, and will be ignored, allowing you to add aliases anywhere in your code:
|
375
|
-
```
|
415
|
+
```yaml
|
376
416
|
# Array Style
|
377
417
|
- /aliases:
|
378
418
|
soda_flavor: &soda_flavor
|
@@ -398,7 +438,8 @@ coke:
|
|
398
438
|
name: Coke
|
399
439
|
flavor: *soda_flavor
|
400
440
|
price: *soda_price
|
401
|
-
|
441
|
+
```
|
442
|
+
```ruby
|
402
443
|
class Soda < ActiveYaml::Base
|
403
444
|
include ActiveYaml::Aliases
|
404
445
|
end
|
@@ -410,14 +451,20 @@ Soda.first.price # => 1.0
|
|
410
451
|
|
411
452
|
### Using ERB ruby in YAML
|
412
453
|
|
413
|
-
Embedded ruby can
|
454
|
+
Embedded ruby can be used in ActiveYaml using erb brackets `<% %>` and `<%= %>` to set the result of a ruby operation as a value in the yaml file.
|
414
455
|
|
415
|
-
```
|
456
|
+
```yaml
|
416
457
|
- id: 1
|
417
458
|
email: <%= "user#{rand(100)}@email.com" %>
|
418
459
|
password: <%= ENV['USER_PASSWORD'] %>
|
419
460
|
```
|
420
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
|
+
|
421
468
|
## ActiveJSON
|
422
469
|
|
423
470
|
If you want to store your data in JSON files, just inherit from ActiveJSON and specify your path information:
|
@@ -482,7 +529,7 @@ class Country < ActiveFile::Base
|
|
482
529
|
|
483
530
|
class << self
|
484
531
|
def extension
|
485
|
-
"
|
532
|
+
"super_secret"
|
486
533
|
end
|
487
534
|
|
488
535
|
def load_file
|
@@ -577,10 +624,6 @@ To make users' lives easier, please maintain support for:
|
|
577
624
|
* Ruby 2.4
|
578
625
|
* ActiveRecord/ActiveSupport from 5.0 through edge
|
579
626
|
|
580
|
-
To that end, run specs against all rubies before committing:
|
581
|
-
|
582
|
-
wwtd
|
583
|
-
|
584
627
|
Once appraisal passes in all supported rubies, follow these steps to release a new version of active_hash:
|
585
628
|
|
586
629
|
* update the changelog with a brief summary of the changes that are included in the release
|
data/active_hash.gemspec
CHANGED
@@ -33,11 +33,18 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.email = %q{jeff@zilkey.com}
|
34
34
|
s.summary = %q{An ActiveRecord-like model that uses a hash or file as a datasource}
|
35
35
|
s.description = %q{Includes the ability to specify data using hashes, yml files or JSON files}
|
36
|
-
s.homepage = %q{http://github.com/
|
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)
|
@@ -47,12 +50,16 @@ module ActiveFile
|
|
47
50
|
protected :actual_root_path
|
48
51
|
|
49
52
|
[:find, :find_by_id, :all, :where, :method_missing].each do |method|
|
50
|
-
define_method(method) do |*args|
|
53
|
+
define_method(method) do |*args, &block|
|
51
54
|
reload unless data_loaded
|
52
|
-
return super(*args)
|
55
|
+
return super(*args, &block)
|
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
|