yaml_record 0.0.2 → 0.0.3
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.
- data/README.md +4 -0
- data/lib/yaml_record/base.rb +14 -4
- data/lib/yaml_record/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -171,6 +171,10 @@ Created at Miso by Nico Taing and Nathan Esquenazi
|
|
171
171
|
|
172
172
|
Contributors and patches are welcome! Please send a pull request!
|
173
173
|
|
174
|
+
## Notes ##
|
175
|
+
|
176
|
+
There is already an excellent project for YAML persistence if you are using [Datamapper](https://github.com/datamapper/dm-yaml-adapter). In the situation in which we were using DM and [Padrino](http://padrinorb.com), this would surely be a better choice. But if you are using ActiveRecord and Rails, this library is a lightweight and standalone solution.
|
177
|
+
|
174
178
|
## License ##
|
175
179
|
|
176
180
|
YAML Record is Copyright © 2011 Nico Taing, Miso. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/lib/yaml_record/base.rb
CHANGED
@@ -212,11 +212,13 @@ module YamlRecord
|
|
212
212
|
end
|
213
213
|
|
214
214
|
# Find YamlRecord instance given attribute name and expected value
|
215
|
+
# Supports checking inclusion for array based values
|
215
216
|
# Returns instance if found; false otherwise
|
216
217
|
#
|
217
218
|
# === Example:
|
218
219
|
#
|
219
|
-
# Post.find_by_attribute(:foo, "bar")
|
220
|
+
# Post.find_by_attribute(:foo, "bar") => @post
|
221
|
+
# Post.find_by_attribute(:some_list, "item") => @post
|
220
222
|
#
|
221
223
|
def self.find_by_attribute(attribute, expected_value)
|
222
224
|
self.all.find do |record|
|
@@ -248,11 +250,13 @@ module YamlRecord
|
|
248
250
|
# === Example:
|
249
251
|
#
|
250
252
|
# Post.all => [@post1, @post2, ...]
|
253
|
+
# Post.all(true) => (...force reload...)
|
251
254
|
#
|
252
|
-
def self.all
|
255
|
+
def self.all(reload=false)
|
256
|
+
@records = nil if reload
|
253
257
|
@records ||= begin
|
254
|
-
raw_items = YAML.load_file(source)
|
255
|
-
raw_items
|
258
|
+
raw_items = YAML.load_file(source) || []
|
259
|
+
raw_items.map { |item| self.new(item.merge(:persisted => true)) }
|
256
260
|
end
|
257
261
|
end
|
258
262
|
|
@@ -327,6 +331,12 @@ module YamlRecord
|
|
327
331
|
file ? @file = (file.to_s + ".yml") : @file
|
328
332
|
end
|
329
333
|
|
334
|
+
# Overrides equality to match if matching ids
|
335
|
+
#
|
336
|
+
def ==(comparison_record)
|
337
|
+
self.id == comparison_record.id
|
338
|
+
end
|
339
|
+
|
330
340
|
protected
|
331
341
|
|
332
342
|
# Validates each persisted attributes
|
data/lib/yaml_record/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nico Taing
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-13 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activesupport
|