cooler 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cooler (0.0.1)
5
- activesupport (~> 3.2.0)
4
+ cooler (0.0.2)
5
+ activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -31,8 +31,8 @@ PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
- autotest (~> 4.4.0)
34
+ autotest (~> 4.4.6)
35
35
  cooler!
36
36
  rake
37
- rr (~> 1.0.0)
37
+ rr (~> 1.0.4)
38
38
  rspec (~> 2.12.0)
data/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ <img src="http://i.imgur.com/qiNrL.jpg" alt="Cooler" align="right">
2
+
1
3
  # Cooler
2
4
 
5
+ _The Good-Hearted Leader_
6
+
7
+ > Cooler Howard Smith has an outgoing and mellow personality and always keeps his
8
+ > head up even in the most daring situations. He is smart, laid-back, friendly,
9
+ > witty, and usually optimistic even when things get serious.
10
+
3
11
  A mini ORM, agnostic to key value store databases.
data/cooler.gemspec CHANGED
@@ -10,16 +10,16 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["ivan@mohound.com"]
11
11
  gem.description = %q{Mini ORM, agnostic to key value store databases}
12
12
  gem.summary = %q{Mini ORM, agnostic to key value store databases}
13
- gem.homepage = "http://github.com/mohound/coolio"
13
+ gem.homepage = "http://github.com/mohound/cooler"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
+ gem.add_dependency('activesupport', '>= 3.0.0')
20
21
 
21
- gem.add_dependency('activesupport', '~> 3.2.0')
22
22
  gem.add_development_dependency('rspec', '~> 2.12.0')
23
- gem.add_development_dependency('rr', '~> 1.0.0')
24
- gem.add_development_dependency('autotest', '~> 4.4.0')
23
+ gem.add_development_dependency('rr', '~> 1.0.4')
24
+ gem.add_development_dependency('autotest', '~> 4.4.6')
25
25
  end
data/lib/cooler/errors.rb CHANGED
@@ -1,5 +1,13 @@
1
1
  module Cooler
2
2
  class NotFound < NameError
3
- def http_status; 404 end
3
+ def http_status
4
+ 404
5
+ end
6
+ end
7
+
8
+ class InvalidRecord < StandardError
9
+ def http_status
10
+ 406
11
+ end
4
12
  end
5
13
  end
data/lib/cooler/model.rb CHANGED
@@ -62,11 +62,11 @@ module Cooler
62
62
  # default :app_key, lambda { |install| install.app.key }
63
63
  #
64
64
  # Returns nothing.
65
- # Raises an exception if attribute does not exist.
65
+ # Raises NameError if attribute does not exist.
66
66
  def default(attr, value, &block)
67
67
  unless instance_methods.include?("#{attr}=".to_sym) &&
68
68
  instance_methods.include?(attr.to_sym)
69
- raise "Unknown attribute #{attr}"
69
+ raise NameError, "Unknown attribute #{attr}"
70
70
  end
71
71
  @default_values[attr.to_sym] = value || block
72
72
  end
@@ -91,9 +91,10 @@ module Cooler
91
91
  # # => Gets object with key: 'install_123'
92
92
  #
93
93
  # Return a Model instance or nothing if not found.
94
+ # Raises NameError, if searching by key and key not defined.
94
95
  def get(key)
95
96
  if Hash === key
96
- raise 'Key not defined' unless @key_block
97
+ raise NameError, 'Key not defined' unless @key_block
97
98
  key = @key_block.(OpenStruct.new(key))
98
99
  end
99
100
  result = Cooler::Adapter.get.(key) and new(key, result)
@@ -172,6 +173,15 @@ module Cooler
172
173
  !Cooler::Adapter.get.(_key).nil?
173
174
  end
174
175
 
176
+ # Saves persisted attributes to the database. Raises an exception if
177
+ # not able to save it.
178
+ #
179
+ # Returns nothing.
180
+ # Raises Cooler::InvalidRecord if not able to save it.
181
+ def save!
182
+ raise Cooler::InvalidRecord unless save
183
+ end
184
+
175
185
  private
176
186
  def set_default_values
177
187
  self.class.default_values.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module Cooler
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -26,7 +26,7 @@ describe Cooler::Model do
26
26
  end
27
27
  end
28
28
 
29
- describe 'key' do
29
+ describe '#key' do
30
30
  it 'should set its key to a new format' do
31
31
  TestModelNewKey.key { |i| "foo_bar_#{i.foo}" }
32
32
  t = TestModelNewKey.new(foo: 'baaar')
@@ -34,7 +34,7 @@ describe Cooler::Model do
34
34
  end
35
35
  end
36
36
 
37
- describe '_key' do
37
+ describe '._key' do
38
38
  it 'should be the passed key' do
39
39
  instance = TestModel.new('keykey')
40
40
  instance._key.should == 'keykey'
@@ -58,7 +58,7 @@ describe Cooler::Model do
58
58
  end
59
59
  end
60
60
 
61
- describe 'get' do
61
+ describe '#get' do
62
62
  it "should return the instance if Adapter's get block returns something" do
63
63
  mock(Cooler::Adapter).get do
64
64
  ->(key) { key.should == 'test_bacon' && { foo: 'bar' } }
@@ -89,7 +89,7 @@ describe Cooler::Model do
89
89
  end
90
90
  end
91
91
 
92
- describe 'get!' do
92
+ describe '#get!' do
93
93
  it 'should return the instance if found by Adapter' do
94
94
  mock(Cooler::Adapter).get do
95
95
  ->(k) { k.should == 'test_bacon' && { foo: 'bar' } }
@@ -106,7 +106,7 @@ describe Cooler::Model do
106
106
  end
107
107
  end
108
108
 
109
- describe 'attributes=' do
109
+ describe '.attributes=' do
110
110
  before(:each) do
111
111
  @instance = TestModelUsingAttrAccessors.new
112
112
  end
@@ -133,7 +133,7 @@ describe Cooler::Model do
133
133
  end
134
134
  end
135
135
 
136
- describe 'serializable_hash' do
136
+ describe '.serializable_hash' do
137
137
  it 'should only include class properties' do
138
138
  instance = TestModelUsingAttrAccessors.new(foo: 'bar', bacon: 'CHUNKY')
139
139
  instance.serializable_hash.keys.should_not include(:bacon)
@@ -150,7 +150,7 @@ describe Cooler::Model do
150
150
  end
151
151
  end
152
152
 
153
- describe 'default' do
153
+ describe '#default' do
154
154
  it 'should raise an exception if no such attribute' do
155
155
  expect { TestModelWithDefaultValues.default :chunky }.
156
156
  to raise_error
@@ -190,7 +190,14 @@ describe Cooler::Model do
190
190
  end
191
191
  end
192
192
 
193
- describe 'save' do
193
+ describe '.save!' do
194
+ it 'should raise an exception if not saved' do
195
+ mock(instance = TestModelForSave.new).save { false }
196
+ expect { instance.save! }.to raise_error(Cooler::InvalidRecord)
197
+ end
198
+ end
199
+
200
+ describe '.save' do
194
201
  it "should call Adapter's set to save its attributes and fail" do
195
202
  instance = TestModelForSave.new(foo: 'bar', bar: 'BAR')
196
203
  mock(Cooler::Adapter).set do
@@ -216,7 +223,7 @@ describe Cooler::Model do
216
223
  end
217
224
  end
218
225
 
219
- describe 'create' do
226
+ describe '.create' do
220
227
  it 'should call Adapter to save its attributes' do
221
228
  mock(Cooler::Adapter).set do
222
229
  ->(key, value) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cooler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,17 +16,17 @@ dependencies:
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.0
21
+ version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.0
29
+ version: 3.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.0
53
+ version: 1.0.4
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.0
61
+ version: 1.0.4
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: autotest
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 4.4.0
69
+ version: 4.4.6
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 4.4.0
77
+ version: 4.4.6
78
78
  description: Mini ORM, agnostic to key value store databases
79
79
  email:
80
80
  - ivan@mohound.com
@@ -97,7 +97,7 @@ files:
97
97
  - spec/cooler/model_spec.rb
98
98
  - spec/spec_helper.rb
99
99
  - spec/support/test_models.rb
100
- homepage: http://github.com/mohound/coolio
100
+ homepage: http://github.com/mohound/cooler
101
101
  licenses: []
102
102
  post_install_message:
103
103
  rdoc_options: []
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: 2911025146145919076
114
+ hash: -3025709922472475179
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 2911025146145919076
123
+ hash: -3025709922472475179
124
124
  requirements: []
125
125
  rubyforge_project:
126
126
  rubygems_version: 1.8.23