passive_record 0.1.3 → 0.1.4
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/lib/passive_record/core/identifier.rb +3 -2
- data/lib/passive_record/version.rb +1 -1
- data/lib/passive_record.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9758b35c579130bfb3877e1910364dae4bf359d5
|
4
|
+
data.tar.gz: 4bd1391ad39cc312bf5dd58f81ef39dc1125df92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e3651c0bee0ea596468778ea80f2b3db759cd4dc7458e57579f5cfef1762f9e632499555b62afa91568d777a208bbcc25ee5a23826427ff953f840d3f47b2a4
|
7
|
+
data.tar.gz: 681b2428d222b851d08b96dd60cc6f897b64d71adb77bc1c9e3273663780511c92fccee33d7e90a60d0a1d13ed4d3f6c93047ba43130459d0cb26f2c6952590c
|
data/lib/passive_record.rb
CHANGED
@@ -24,8 +24,17 @@ module PassiveRecord
|
|
24
24
|
|
25
25
|
module InstanceMethods
|
26
26
|
def inspect
|
27
|
-
|
27
|
+
pretty_vars = instance_variables_hash.map do |k,v|
|
28
|
+
"#{k.to_s.gsub(/^\@/,'')}: #{v.inspect}"
|
29
|
+
end.join(', ')
|
30
|
+
"#{self.class.name} (#{pretty_vars})"
|
28
31
|
end
|
32
|
+
|
33
|
+
# from http://stackoverflow.com/a/8417341/90042
|
34
|
+
def instance_variables_hash
|
35
|
+
Hash[instance_variables.map { |name| [name, instance_variable_get(name)] } ]
|
36
|
+
end
|
37
|
+
|
29
38
|
def relata
|
30
39
|
@relata ||= self.class.associations.map do |assn|
|
31
40
|
assn.to_relation(self)
|
@@ -91,6 +100,14 @@ module PassiveRecord
|
|
91
100
|
all.last
|
92
101
|
end
|
93
102
|
|
103
|
+
def find(id_or_ids)
|
104
|
+
if id_or_ids.is_a?(Array)
|
105
|
+
find_by_ids(id_or_ids)
|
106
|
+
else
|
107
|
+
find_by_id(id_or_ids)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
94
111
|
def find_by(conditions)
|
95
112
|
if conditions.is_a?(Identifier)
|
96
113
|
find_by_id(conditions)
|
@@ -117,7 +134,7 @@ module PassiveRecord
|
|
117
134
|
instance = new
|
118
135
|
|
119
136
|
instance.singleton_class.class_eval { attr_accessor :id }
|
120
|
-
instance.send(:"id=", Identifier.generate)
|
137
|
+
instance.send(:"id=", Identifier.generate(self))
|
121
138
|
|
122
139
|
register(instance)
|
123
140
|
|