superstore 1.0.12 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/lib/superstore/adapters/cassandra_adapter.rb +1 -1
- data/lib/superstore/adapters/hstore_adapter.rb +1 -1
- data/lib/superstore/callbacks.rb +2 -2
- data/lib/superstore/model.rb +13 -3
- data/lib/superstore/persistence.rb +13 -9
- data/superstore.gemspec +1 -1
- data/test/support/pg.rb +3 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/attribute_methods/typecasting_test.rb +3 -3
- data/test/unit/base_test.rb +2 -2
- data/test/unit/callbacks_test.rb +1 -1
- data/test/unit/persistence_test.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47de82fc0ed193ae01bdfd2a66b316a9c9ea0f98
|
4
|
+
data.tar.gz: d55d96966d9d241acbc653731797080a053dd6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7be9c8c180e858358c94eba1e143588bba69ee1631321df79ffc4d6098b399fa25d565c8dcbe48d7a0970bc8f80f9dc91ff75597669a2bdb04b601f5fe227bb8
|
7
|
+
data.tar.gz: 8a16760f19d67f19061e73f71bd1857002b7ba8923c4d031f9044ca630627860be6a1d0ea11b313ff7a4c0567392e64cf6f46702eb5e98c7bcee7c348d4ac359
|
data/README.md
CHANGED
@@ -28,6 +28,15 @@ class Widget < Superstore::Base
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
```
|
31
|
+
|
32
|
+
The table name defaults to the case-sensitive, pluralized name of the model class. To specify a
|
33
|
+
custom name, set the ```table_name``` attribute on the class:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class MyWidget < Superstore::Base
|
37
|
+
table_name = 'my_widgets'
|
38
|
+
end
|
39
|
+
```
|
31
40
|
## Using with Cassandra
|
32
41
|
|
33
42
|
Add the cassandra-cql gem to Gemfile:
|
@@ -35,7 +44,7 @@ Add the cassandra-cql gem to Gemfile:
|
|
35
44
|
```ruby
|
36
45
|
gem 'cassandra-cql'
|
37
46
|
```
|
38
|
-
|
47
|
+
|
39
48
|
Add a config/superstore.yml:
|
40
49
|
|
41
50
|
```yaml
|
@@ -55,7 +64,7 @@ Add the pg gem to your Gemfile:
|
|
55
64
|
```ruby
|
56
65
|
gem 'pg'
|
57
66
|
```
|
58
|
-
|
67
|
+
|
59
68
|
And a config/superstore.yml:
|
60
69
|
|
61
70
|
```yaml
|
@@ -72,7 +81,7 @@ widget = Widget.new
|
|
72
81
|
widget.valid?
|
73
82
|
widget = Widget.create(name: 'Acme', price: 100)
|
74
83
|
widget.update_attribute(:price, 1200)
|
75
|
-
widget.
|
84
|
+
widget.update(price: 1200, name: 'Acme Corporation')
|
76
85
|
widget.attributes = {price: 300}
|
77
86
|
widget.price_was
|
78
87
|
widget.save
|
@@ -97,4 +106,4 @@ Some lightweight scoping features are available:
|
|
97
106
|
Widget.where('color' => 'red')
|
98
107
|
Widget.select(['name', 'color'])
|
99
108
|
Widget.limit(10)
|
100
|
-
```
|
109
|
+
```
|
data/lib/superstore/callbacks.rb
CHANGED
@@ -18,11 +18,11 @@ module Superstore
|
|
18
18
|
run_callbacks(:save) { super }
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def create_self #:nodoc:
|
22
22
|
run_callbacks(:create) { super }
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def update_self(*) #:nodoc:
|
26
26
|
run_callbacks(:update) { super }
|
27
27
|
end
|
28
28
|
end
|
data/lib/superstore/model.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
module Superstore
|
2
2
|
module Model
|
3
|
-
def
|
4
|
-
@
|
3
|
+
def table_name=(table_name)
|
4
|
+
@table_name = table_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def table_name
|
8
|
+
@table_name ||= base_class.name.pluralize
|
5
9
|
end
|
6
10
|
|
7
11
|
def column_family
|
8
|
-
|
12
|
+
warn '`column_family` is deprecated & will be removed in superstore 2.0. Use `table_name` instead.'
|
13
|
+
table_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def column_family=(table_name)
|
17
|
+
warn '`column_family=` is deprecated & will be removed in superstore 2.0. Use `table_name=` instead.'
|
18
|
+
self.table_name = table_name
|
9
19
|
end
|
10
20
|
|
11
21
|
def base_class
|
@@ -8,11 +8,11 @@ module Superstore
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def remove(ids)
|
11
|
-
adapter.delete
|
11
|
+
adapter.delete table_name, ids
|
12
12
|
end
|
13
13
|
|
14
14
|
def delete_all
|
15
|
-
adapter.execute "TRUNCATE #{
|
15
|
+
adapter.execute "TRUNCATE #{table_name}"
|
16
16
|
end
|
17
17
|
|
18
18
|
def create(attributes = {}, &block)
|
@@ -22,11 +22,11 @@ module Superstore
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def insert_record(id, attributes)
|
25
|
-
adapter.insert
|
25
|
+
adapter.insert table_name, id, encode_attributes(attributes)
|
26
26
|
end
|
27
27
|
|
28
28
|
def update_record(id, attributes)
|
29
|
-
adapter.update
|
29
|
+
adapter.update table_name, id, encode_attributes(attributes)
|
30
30
|
end
|
31
31
|
|
32
32
|
def batching?
|
@@ -96,7 +96,7 @@ module Superstore
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def save(*)
|
99
|
-
new_record? ?
|
99
|
+
new_record? ? create_self : update_self
|
100
100
|
end
|
101
101
|
|
102
102
|
def destroy
|
@@ -110,16 +110,20 @@ module Superstore
|
|
110
110
|
save(validate: false)
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def update(attributes)
|
114
114
|
self.attributes = attributes
|
115
115
|
save
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
alias update_attributes update
|
119
|
+
|
120
|
+
def update!(attributes)
|
119
121
|
self.attributes = attributes
|
120
122
|
save!
|
121
123
|
end
|
122
124
|
|
125
|
+
alias update_attributes! update!
|
126
|
+
|
123
127
|
def becomes(klass)
|
124
128
|
became = klass.new
|
125
129
|
became.instance_variable_set("@attributes", @attributes)
|
@@ -136,12 +140,12 @@ module Superstore
|
|
136
140
|
|
137
141
|
private
|
138
142
|
|
139
|
-
def
|
143
|
+
def create_self
|
140
144
|
@new_record = false
|
141
145
|
write :insert_record
|
142
146
|
end
|
143
147
|
|
144
|
-
def
|
148
|
+
def update_self
|
145
149
|
write :update_record
|
146
150
|
end
|
147
151
|
|
data/superstore.gemspec
CHANGED
data/test/support/pg.rb
CHANGED
@@ -7,7 +7,9 @@ class PGInitializer
|
|
7
7
|
'encoding' => 'unicode',
|
8
8
|
'database' => 'superstore_test',
|
9
9
|
'pool' => 5,
|
10
|
-
'
|
10
|
+
'host' => 'localhost',
|
11
|
+
'password' => 'postgres',
|
12
|
+
'username' => 'postgres'
|
11
13
|
}
|
12
14
|
|
13
15
|
ActiveRecord::Base.configurations = { test: config }
|
data/test/test_helper.rb
CHANGED
@@ -8,7 +8,7 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class TestIssue < Superstore::Base
|
11
|
-
self.
|
11
|
+
self.table_name = 'Issues'
|
12
12
|
|
13
13
|
attribute :custom_column, type: CustomType, coder: CustomCoder
|
14
14
|
boolean :enabled
|
@@ -92,7 +92,7 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
|
|
92
92
|
|
93
93
|
test 'multiple attributes definition' do
|
94
94
|
class MultipleAttributesIssue < Superstore::Base
|
95
|
-
self.
|
95
|
+
self.table_name = 'Issues'
|
96
96
|
end
|
97
97
|
|
98
98
|
assert_nothing_raised {
|
@@ -105,7 +105,7 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
|
|
105
105
|
|
106
106
|
test 'multiple attributes with options' do
|
107
107
|
class MultipleAttributesIssue < Superstore::Base
|
108
|
-
self.
|
108
|
+
self.table_name = 'Issues'
|
109
109
|
end
|
110
110
|
|
111
111
|
MultipleAttributesIssue.expects(:attribute).with(:hello, { :unique => :true, :type => :string })
|
data/test/unit/base_test.rb
CHANGED
@@ -14,7 +14,7 @@ class Superstore::BaseTest < Superstore::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'column family' do
|
17
|
-
assert_equal 'Superstore::BaseTest::Sons', Son.
|
18
|
-
assert_equal 'Superstore::BaseTest::Sons', Grandson.
|
17
|
+
assert_equal 'Superstore::BaseTest::Sons', Son.table_name
|
18
|
+
assert_equal 'Superstore::BaseTest::Sons', Grandson.table_name
|
19
19
|
end
|
20
20
|
end
|
data/test/unit/callbacks_test.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class Superstore::CallbacksTest < Superstore::TestCase
|
4
4
|
class TestIssue < Superstore::Base
|
5
|
-
self.
|
5
|
+
self.table_name = 'Issues'
|
6
6
|
string :description
|
7
7
|
|
8
8
|
%w(before_validation after_validation after_save after_create after_update after_destroy).each do |method|
|
@@ -111,15 +111,15 @@ class Superstore::PersistenceTest < Superstore::TestCase
|
|
111
111
|
assert_equal 'lol', issue.description
|
112
112
|
end
|
113
113
|
|
114
|
-
test '
|
114
|
+
test 'update' do
|
115
115
|
issue = Issue.create
|
116
|
-
issue.
|
116
|
+
issue.update(description: 'lol')
|
117
117
|
|
118
118
|
assert !issue.changed?
|
119
119
|
assert_equal 'lol', issue.description
|
120
120
|
end
|
121
121
|
|
122
|
-
test '
|
122
|
+
test 'update!' do
|
123
123
|
begin
|
124
124
|
Issue.validates(:description, presence: true)
|
125
125
|
|
@@ -127,7 +127,7 @@ class Superstore::PersistenceTest < Superstore::TestCase
|
|
127
127
|
issue.save!
|
128
128
|
|
129
129
|
assert_raise Superstore::RecordInvalid do
|
130
|
-
issue.
|
130
|
+
issue.update! description: ''
|
131
131
|
end
|
132
132
|
ensure
|
133
133
|
Issue.reset_callbacks(:validate)
|
@@ -137,7 +137,7 @@ class Superstore::PersistenceTest < Superstore::TestCase
|
|
137
137
|
test 'update nil attributes' do
|
138
138
|
issue = Issue.create(title: 'I rule', description: 'lololol')
|
139
139
|
|
140
|
-
issue.
|
140
|
+
issue.update title: nil
|
141
141
|
|
142
142
|
issue = Issue.find issue.id
|
143
143
|
assert_nil issue.title
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|