ephemeral 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/ephemeral.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ephemeral"
8
- s.version = "1.2.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Ehmke"]
12
- s.date = "2012-09-24"
12
+ s.date = "2013-09-23"
13
13
  s.description = "Ephemeral lets you define one-to-many relationships between in-memory objects, with ORM-like support for where clauses and chainable scopes."
14
14
  s.email = "corey@idolhands.com"
15
15
  s.extra_rdoc_files = [
@@ -7,21 +7,31 @@ module Ephemeral
7
7
 
8
8
  def self.included(base)
9
9
  base.extend ClassMethods
10
- base.send(:attr_accessor, :collections, :relations)
10
+ base.send(:attr_accessor, :relations)
11
+ base.send(:attr_writer, :collections)
12
+ end
13
+
14
+ def collections
15
+ @collections ||= {}
11
16
  end
12
17
 
13
18
  module ClassMethods
14
19
 
15
- def collects(name, args={})
20
+ def collects(name=nil, args={})
21
+ return @@collections unless name
16
22
  class_name = args[:class_name] || name.to_s.classify
23
+ @@collections ||= {}
24
+ @@collections[name] = Ephemeral::Collection.new(class_name)
25
+
17
26
  self.send :define_method, name do
18
- self.collections ||= {}
19
27
  self.collections[class_name] ||= Ephemeral::Collection.new(class_name)
28
+ return [] if self.collections[class_name].empty?
29
+ self.collections[class_name]
20
30
  end
21
31
  self.send :define_method, "#{name}=" do |objects|
22
- self.collections ||= {}
23
32
  self.collections[class_name] = Ephemeral::Collection.new(class_name, objects)
24
33
  end
34
+
25
35
  end
26
36
 
27
37
  def has_one(name, args={})
@@ -44,12 +44,12 @@ describe Ephemeral do
44
44
  context 'collections' do
45
45
 
46
46
  it 'defines a collection' do
47
- Collector.new.rarities.klass.should == Rarity
48
- Collector.new.antiques.klass.should == Antique
47
+ Collector.collects[:rarities].klass.should == Rarity
48
+ Collector.collects[:antiques].klass.should == Antique
49
49
  end
50
50
 
51
51
  it 'accepts a class name' do
52
- Collector.new.junk.klass.should == NotCollectible
52
+ Collector.collects[:junk].klass.should == NotCollectible
53
53
  end
54
54
 
55
55
  it 'creates a setter' do
@@ -79,12 +79,15 @@ describe Ephemeral do
79
79
 
80
80
  context 'relations' do
81
81
 
82
- before :each do
83
- @antique = Antique.new(:name => 'Model T Ford', :item_count => 1, :picker => {:name => "Mike Wolfe"} )
82
+ it 'initializes with a hash' do
83
+ antique = Antique.new(:name => 'Model T Ford', :item_count => 1, :picker => {:name => "Mike Wolfe"} )
84
+ antique.picker.name.should == "Mike Wolfe"
84
85
  end
85
86
 
86
87
  it 'initializes with a materialized object' do
87
- @antique.picker.name.should == "Mike Wolfe"
88
+ picker = Picker.new(:name => 'Mike Wolfe')
89
+ antique = Antique.new(:name => 'Model T Ford', :item_count => 1, :picker => picker )
90
+ antique.picker.name.should == "Mike Wolfe"
88
91
  end
89
92
 
90
93
  end
@@ -124,6 +127,10 @@ describe Ephemeral do
124
127
 
125
128
  end
126
129
 
130
+ it 'initializes with an empty array' do
131
+ Collector.new.rarities.should == []
132
+ end
133
+
127
134
  it 'performs a where' do
128
135
  @collector.rarities.where(:name => 'Paychecks').should_not be_blank
129
136
  @collector.antiques.where(:name => 'Trading Cards').should_not be_blank
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ephemeral
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -1586023366873335519
130
+ hash: 1892452542155194633
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements: