ephemeral 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/ephemeral.gemspec +62 -0
- data/lib/ephemeral/base.rb +5 -3
- data/spec/ephemeral_spec.rb +31 -17
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.0.0
|
data/ephemeral.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ephemeral"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Corey Ehmke"]
|
12
|
+
s.date = "2012-08-17"
|
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
|
+
s.email = "corey@idolhands.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"ephemeral.gemspec",
|
27
|
+
"lib/ephemeral.rb",
|
28
|
+
"lib/ephemeral/base.rb",
|
29
|
+
"lib/ephemeral/collection.rb",
|
30
|
+
"spec/ephemeral_spec.rb"
|
31
|
+
]
|
32
|
+
s.homepage = "http://github.com/Bantik/ephemeral"
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = "1.8.24"
|
36
|
+
s.summary = "Ephemeral is an ODM for in-memory collections of objects."
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
44
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
49
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/ephemeral/base.rb
CHANGED
@@ -7,7 +7,7 @@ module Ephemeral
|
|
7
7
|
|
8
8
|
def self.included(base)
|
9
9
|
base.extend ClassMethods
|
10
|
-
base.send(:attr_accessor, :
|
10
|
+
base.send(:attr_accessor, :collections)
|
11
11
|
end
|
12
12
|
|
13
13
|
module ClassMethods
|
@@ -15,10 +15,12 @@ module Ephemeral
|
|
15
15
|
def collects(name, args={})
|
16
16
|
class_name = args[:class_name] || name.to_s.classify
|
17
17
|
self.send :define_method, name do
|
18
|
-
self.
|
18
|
+
self.collections ||= {}
|
19
|
+
self.collections[class_name] ||= Ephemeral::Collection.new(class_name)
|
19
20
|
end
|
20
21
|
self.send :define_method, "#{name}=" do |objects|
|
21
|
-
self.
|
22
|
+
self.collections ||= {}
|
23
|
+
self.collections[class_name] = Ephemeral::Collection.new(class_name, objects)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
data/spec/ephemeral_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'ephemeral'
|
2
2
|
|
3
|
-
class
|
3
|
+
class Rarity
|
4
4
|
include Ephemeral::Base
|
5
5
|
attr_accessor :name, :item_count
|
6
6
|
scope :foos, {:name => 'foo'}
|
@@ -9,6 +9,12 @@ class Collectible
|
|
9
9
|
def initialize(args={}); args.each{|k,v| self.send("#{k}=", v)}; end
|
10
10
|
end
|
11
11
|
|
12
|
+
class Antique
|
13
|
+
include Ephemeral::Base
|
14
|
+
attr_accessor :name, :item_count
|
15
|
+
def initialize(args={}); args.each{|k,v| self.send("#{k}=", v)}; end
|
16
|
+
end
|
17
|
+
|
12
18
|
class NotCollectible
|
13
19
|
include Ephemeral::Base
|
14
20
|
attr_accessor :name
|
@@ -18,7 +24,8 @@ end
|
|
18
24
|
class Collector
|
19
25
|
include Ephemeral::Base
|
20
26
|
attr_accessor :name
|
21
|
-
collects :
|
27
|
+
collects :rarities
|
28
|
+
collects :antiques
|
22
29
|
collects :junk, :class_name => 'NotCollectible'
|
23
30
|
def initialize(args={}); args.each{|k,v| self.send("#{k}=", v)}; end
|
24
31
|
end
|
@@ -28,7 +35,8 @@ describe Ephemeral do
|
|
28
35
|
context 'class methods' do
|
29
36
|
|
30
37
|
it 'defines a collection' do
|
31
|
-
Collector.new.
|
38
|
+
Collector.new.rarities.klass.should == Rarity
|
39
|
+
Collector.new.antiques.klass.should == Antique
|
32
40
|
end
|
33
41
|
|
34
42
|
it 'accepts a class name' do
|
@@ -36,15 +44,15 @@ describe Ephemeral do
|
|
36
44
|
end
|
37
45
|
|
38
46
|
it 'creates a setter' do
|
39
|
-
Collector.new.respond_to?(:
|
47
|
+
Collector.new.respond_to?(:rarities=).should be_true
|
40
48
|
end
|
41
49
|
|
42
50
|
it 'creates a getter' do
|
43
|
-
Collector.new.respond_to?(:
|
51
|
+
Collector.new.respond_to?(:rarities).should be_true
|
44
52
|
end
|
45
53
|
|
46
54
|
it 'registers a scope' do
|
47
|
-
|
55
|
+
Rarity.scopes.include?(:foos).should be_true
|
48
56
|
end
|
49
57
|
|
50
58
|
end
|
@@ -53,14 +61,19 @@ describe Ephemeral do
|
|
53
61
|
|
54
62
|
before :each do
|
55
63
|
|
56
|
-
@
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
@rarities = [
|
65
|
+
Rarity.new(:name => 'Paychecks', :item_count => 1),
|
66
|
+
Rarity.new(:name => 'Paychecks', :item_count => 3),
|
67
|
+
Rarity.new(:name => 'Requisitions', :item_count => 2),
|
68
|
+
]
|
69
|
+
|
70
|
+
@antiques = [
|
71
|
+
Antique.new(:name => 'Trading Cards', :item_count => 100)
|
60
72
|
]
|
61
73
|
|
62
74
|
@collector = Collector.new(:name => 'Hermes')
|
63
|
-
@collector.
|
75
|
+
@collector.rarities = @rarities
|
76
|
+
@collector.antiques = @antiques
|
64
77
|
|
65
78
|
end
|
66
79
|
|
@@ -69,32 +82,33 @@ describe Ephemeral do
|
|
69
82
|
it 'from a setter' do
|
70
83
|
collector = Collector.new(
|
71
84
|
:name => 'from_api',
|
72
|
-
'
|
85
|
+
'rarities' => [
|
73
86
|
{'name' => 'foo'},
|
74
87
|
{'name' => 'bar'}
|
75
88
|
]
|
76
89
|
)
|
77
|
-
collector.
|
90
|
+
collector.rarities.count.should == 2
|
78
91
|
end
|
79
92
|
|
80
93
|
end
|
81
94
|
|
82
95
|
it 'performs a where' do
|
83
|
-
@collector.
|
96
|
+
@collector.rarities.where(:name => 'Paychecks').should_not be_blank
|
97
|
+
@collector.antiques.where(:name => 'Trading Cards').should_not be_blank
|
84
98
|
end
|
85
99
|
|
86
100
|
describe 'scope method' do
|
87
101
|
|
88
102
|
it 'executes a scope' do
|
89
|
-
@collector.
|
103
|
+
@collector.rarities.paychecks.first.should_not be_nil
|
90
104
|
end
|
91
105
|
|
92
106
|
it 'returns a collection' do
|
93
|
-
@collector.
|
107
|
+
@collector.rarities.paychecks.class.name.should == 'Ephemeral::Collection'
|
94
108
|
end
|
95
109
|
|
96
110
|
it 'chains scopes' do
|
97
|
-
@collector.
|
111
|
+
@collector.rarities.paychecks.threes.count.should == 1
|
98
112
|
end
|
99
113
|
|
100
114
|
end
|
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:
|
4
|
+
version: 1.0.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-08-
|
12
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- README.md
|
107
107
|
- Rakefile
|
108
108
|
- VERSION
|
109
|
+
- ephemeral.gemspec
|
109
110
|
- lib/ephemeral.rb
|
110
111
|
- lib/ephemeral/base.rb
|
111
112
|
- lib/ephemeral/collection.rb
|
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
segments:
|
127
128
|
- 0
|
128
|
-
hash:
|
129
|
+
hash: 1446140040107562774
|
129
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
131
|
none: false
|
131
132
|
requirements:
|