passive_record 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 028f8b542632306cf8fffbcb2cf7140e98220ffe
4
- data.tar.gz: b3634261a2df5095b0663d79386a07fb2947c5ff
3
+ metadata.gz: 9758b35c579130bfb3877e1910364dae4bf359d5
4
+ data.tar.gz: 4bd1391ad39cc312bf5dd58f81ef39dc1125df92
5
5
  SHA512:
6
- metadata.gz: 8d69bf45706fab2747b712c27b24d7189e6440cfafc1c3dc8b17fed3204213cbfb033f1fedd1efbb7e6754e1371cf4025c9c7b10335b037be666eec9554e9fc6
7
- data.tar.gz: fe63859955c044abba1e8ecd06d8affe86162a6f6e4fd83e1e7e258743b9da51542f25b359b8ae8c6fdf04716039ea44612b1e8489150432b4e76a52b2d62ff5
6
+ metadata.gz: 1e3651c0bee0ea596468778ea80f2b3db759cd4dc7458e57579f5cfef1762f9e632499555b62afa91568d777a208bbcc25ee5a23826427ff953f840d3f47b2a4
7
+ data.tar.gz: 681b2428d222b851d08b96dd60cc6f897b64d71adb77bc1c9e3273663780511c92fccee33d7e90a60d0a1d13ed4d3f6c93047ba43130459d0cb26f2c6952590c
@@ -1,7 +1,8 @@
1
1
  module PassiveRecord
2
2
  class Identifier < Struct.new(:value)
3
- def self.generate
4
- new(SecureRandom.uuid)
3
+ def self.generate(klass)
4
+ new(klass.count+1)
5
+ # TODO maybe config to activate SecureRandom.uuid?
5
6
  end
6
7
 
7
8
  def ==(other_id)
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
@@ -24,8 +24,17 @@ module PassiveRecord
24
24
 
25
25
  module InstanceMethods
26
26
  def inspect
27
- self.class.name + "(#{id.inspect})"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman