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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dbdeea44891e8279235f3499ffc43f2613024ca
4
- data.tar.gz: 23d8acb6c14a91297b758df73ea54557d8ff353d
3
+ metadata.gz: 47de82fc0ed193ae01bdfd2a66b316a9c9ea0f98
4
+ data.tar.gz: d55d96966d9d241acbc653731797080a053dd6e9
5
5
  SHA512:
6
- metadata.gz: 74c765f45c487870d43f97e6ffcf361a81c7e783476c2ad57d8764ce7e9abf54a11577a017e954272ac8900c019ce6e809bc8a750c87da445ce8c72bf48dd61c
7
- data.tar.gz: e35465eeb0a7651c39e419789cee64e30872e27c8675a110b000b80bcf68f562dc08cafc3c9c1ab149e238b8c9607c325fe78410987b61b244ca136251d158e8
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.update_attributes(price: 1200, name: 'Acme Corporation')
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
+ ```
@@ -12,7 +12,7 @@ module Superstore
12
12
 
13
13
  def to_query
14
14
  [
15
- "SELECT #{select_string} FROM #{@scope.klass.column_family}",
15
+ "SELECT #{select_string} FROM #{@scope.klass.table_name}",
16
16
  @adapter.write_option_string,
17
17
  where_string,
18
18
  limit_string
@@ -12,7 +12,7 @@ module Superstore
12
12
 
13
13
  def to_query
14
14
  [
15
- "SELECT #{select_string} FROM #{@scope.klass.column_family}",
15
+ "SELECT #{select_string} FROM #{@scope.klass.table_name}",
16
16
  where_string,
17
17
  order_string,
18
18
  limit_string
@@ -18,11 +18,11 @@ module Superstore
18
18
  run_callbacks(:save) { super }
19
19
  end
20
20
 
21
- def create #:nodoc:
21
+ def create_self #:nodoc:
22
22
  run_callbacks(:create) { super }
23
23
  end
24
24
 
25
- def update(*) #:nodoc:
25
+ def update_self(*) #:nodoc:
26
26
  run_callbacks(:update) { super }
27
27
  end
28
28
  end
@@ -1,11 +1,21 @@
1
1
  module Superstore
2
2
  module Model
3
- def column_family=(column_family)
4
- @column_family = column_family
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
- @column_family ||= base_class.name.pluralize
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 column_family, ids
11
+ adapter.delete table_name, ids
12
12
  end
13
13
 
14
14
  def delete_all
15
- adapter.execute "TRUNCATE #{column_family}"
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 column_family, id, encode_attributes(attributes)
25
+ adapter.insert table_name, id, encode_attributes(attributes)
26
26
  end
27
27
 
28
28
  def update_record(id, attributes)
29
- adapter.update column_family, id, encode_attributes(attributes)
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? ? create : update
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 update_attributes(attributes)
113
+ def update(attributes)
114
114
  self.attributes = attributes
115
115
  save
116
116
  end
117
117
 
118
- def update_attributes!(attributes)
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 create
143
+ def create_self
140
144
  @new_record = false
141
145
  write :insert_record
142
146
  end
143
147
 
144
- def update
148
+ def update_self
145
149
  write :update_record
146
150
  end
147
151
 
data/superstore.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'superstore'
5
- s.version = '1.0.12'
5
+ s.version = '1.1.0'
6
6
  s.description = 'ActiveModel for many attributes'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
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
- 'username' => 'postgres'
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
@@ -20,7 +20,7 @@ module Superstore
20
20
  class TestCase < ActiveSupport::TestCase
21
21
  def temp_object(&block)
22
22
  Class.new(Superstore::Base) do
23
- self.column_family = 'Issues'
23
+ self.table_name = 'Issues'
24
24
  string :force_save
25
25
  before_save { self.force_save = 'junk' }
26
26
 
@@ -8,7 +8,7 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
8
8
  end
9
9
 
10
10
  class TestIssue < Superstore::Base
11
- self.column_family = 'Issues'
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.column_family = 'Issues'
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.column_family = 'Issues'
108
+ self.table_name = 'Issues'
109
109
  end
110
110
 
111
111
  MultipleAttributesIssue.expects(:attribute).with(:hello, { :unique => :true, :type => :string })
@@ -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.column_family
18
- assert_equal 'Superstore::BaseTest::Sons', Grandson.column_family
17
+ assert_equal 'Superstore::BaseTest::Sons', Son.table_name
18
+ assert_equal 'Superstore::BaseTest::Sons', Grandson.table_name
19
19
  end
20
20
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class Superstore::CallbacksTest < Superstore::TestCase
4
4
  class TestIssue < Superstore::Base
5
- self.column_family = 'Issues'
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 'update_attributes' do
114
+ test 'update' do
115
115
  issue = Issue.create
116
- issue.update_attributes(description: 'lol')
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 'update_attributes!' do
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.update_attributes! description: ''
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.update_attributes title: nil
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.12
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-08-05 00:00:00.000000000 Z
12
+ date: 2014-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel