superstore 1.0.2 → 1.0.3

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: ab95c845f31fa3557952125e9db3fb68ec37d8d9
4
- data.tar.gz: 5bea5b3c94a7c172bd6ce97a4a21ea1b5d77a96f
3
+ metadata.gz: 84669dc1d087ef650432331ba37250ac34d475da
4
+ data.tar.gz: 4b9cbfdf901f62b442001cf2d255056b836fc6d5
5
5
  SHA512:
6
- metadata.gz: bf14d4bf4b8fd2d03e1e7627c9facff10ba47d454d2a43e0f26956526112b8914fd4981c56ee6100cce315763e4338c54b03f63c6305ee78ec13aae3a28dfa32
7
- data.tar.gz: 07502ca8fea646f7041ef1c1ad0be27dd643f0dc751eb0a55350a4d8c0d22258c5767afc9fcfc03438c122f125b3301ed0b890cf770adaddefcd9f5c2a29d998
6
+ metadata.gz: 0486ef130ad6e9b9687a95ff025232247768d07e218c653ea37a159b3cbfab3a8a4994cc88f6541ed573aaedb9a8119ad49106ae0462726c28af69cbdbfd7f9d
7
+ data.tar.gz: 400d2752bff7dc31c12dbfbbca412563b79e8853e7f305d4230856c57e15e2a00b366a38f6658029779f82c03f7b58746e7cee887a58b9b3f621aa6ebcb0258e
data/lib/superstore.rb CHANGED
@@ -8,6 +8,7 @@ module Superstore
8
8
  autoload :AttributeMethods
9
9
  autoload :Base
10
10
  autoload :BelongsTo
11
+ autoload :Caching
11
12
  autoload :Callbacks
12
13
  autoload :Connection
13
14
  autoload :Core
@@ -15,7 +15,7 @@ module Superstore
15
15
  "SELECT #{select_string} FROM #{@scope.klass.column_family}",
16
16
  where_string,
17
17
  order_string,
18
- limit_string,
18
+ limit_string
19
19
  ].delete_if(&:blank?) * ' '
20
20
  end
21
21
 
@@ -39,7 +39,10 @@ module Superstore
39
39
  end
40
40
 
41
41
  def order_string
42
- if @scope.id_values.many?
42
+ if @scope.order_values.any?
43
+ orders = @scope.order_values.join(', ')
44
+ "ORDER BY #{orders}"
45
+ elsif @scope.id_values.many?
43
46
  id_orders = @scope.id_values.map { |id| "ID=#{@adapter.quote(id)} DESC" }.join(',')
44
47
  "ORDER BY #{id_orders}"
45
48
  end
@@ -160,4 +163,4 @@ module Superstore
160
163
  end
161
164
  end
162
165
  end
163
- end
166
+ end
@@ -25,6 +25,7 @@ module Superstore
25
25
  include Timestamps
26
26
  include Scoping
27
27
  include Core
28
+ include Caching
28
29
  extend Model
29
30
 
30
31
  end
@@ -0,0 +1,13 @@
1
+ module Superstore
2
+ module Caching
3
+ extend ActiveSupport::Concern
4
+
5
+ def cache_key
6
+ if new_record?
7
+ "#{self.class.model_name.cache_key}/new"
8
+ else
9
+ "#{self.class.model_name.cache_key}/#{id}-#{updated_at}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -40,7 +40,7 @@ module Superstore
40
40
  if self == Base
41
41
  super
42
42
  else
43
- attr_list = @attributes.map do |col, definition| "#{col}: #{definition.type}" end * ', '
43
+ attr_list = attribute_definitions.keys * ', '
44
44
  "#{super}(#{attr_list.truncate(140 * 1.7337)})"
45
45
  end
46
46
  end
@@ -7,7 +7,7 @@ module Superstore
7
7
  include Batches, FinderMethods, QueryMethods
8
8
 
9
9
  attr_accessor :klass
10
- attr_accessor :limit_value, :select_values, :where_values, :id_values
10
+ attr_accessor :limit_value, :select_values, :where_values, :id_values, :order_values
11
11
 
12
12
  def initialize(klass)
13
13
  @klass = klass
@@ -15,6 +15,7 @@ module Superstore
15
15
  @limit_value = nil
16
16
  @select_values = []
17
17
  @where_values = []
18
+ @order_values = []
18
19
  @id_values = []
19
20
  end
20
21
 
@@ -11,7 +11,7 @@ module Superstore
11
11
  batch_size = options.delete(:batch_size) || 1000
12
12
  start_key = nil
13
13
 
14
- scope = limit(batch_size + 1)
14
+ scope = limit(batch_size + 1).order(:id)
15
15
  records = scope.to_a
16
16
 
17
17
  while records.any?
@@ -41,6 +41,15 @@ module Superstore
41
41
  clone.limit! value
42
42
  end
43
43
 
44
+ def order!(*values)
45
+ self.order_values = values.flatten
46
+ self
47
+ end
48
+
49
+ def order(*values)
50
+ clone.order! values
51
+ end
52
+
44
53
  def to_a
45
54
  select_records
46
55
  end
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.2'
5
+ s.version = '1.0.3'
6
6
  s.description = 'ActiveModel for many attributes'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
data/test/test_helper.rb CHANGED
@@ -7,7 +7,7 @@ require 'rails/test_help'
7
7
  require 'mocha/setup'
8
8
 
9
9
  require 'support/pg'
10
- #require 'support/hstore'
10
+ # require 'support/hstore'
11
11
  require 'support/cassandra'
12
12
  require 'support/issue'
13
13
  require 'support/user'
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class Superstore::CachingTest < Superstore::TestCase
4
+ class ::OtherClass < Superstore::Base
5
+ end
6
+
7
+ test 'for a new record' do
8
+ issue = Issue.new
9
+ other_class = OtherClass.new
10
+ assert_equal "issues/new", issue.cache_key
11
+ assert_equal "other_classes/new", other_class.cache_key
12
+ end
13
+
14
+ test 'for a persisted record' do
15
+ updated_at = Time.now
16
+ issue = Issue.create!(id: 1, updated_at: updated_at)
17
+
18
+ assert_equal "issues/1-#{updated_at}", issue.cache_key
19
+ end
20
+ end
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.2
4
+ version: 1.0.3
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-05-30 00:00:00.000000000 Z
12
+ date: 2014-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -68,6 +68,7 @@ files:
68
68
  - lib/superstore/belongs_to/association.rb
69
69
  - lib/superstore/belongs_to/builder.rb
70
70
  - lib/superstore/belongs_to/reflection.rb
71
+ - lib/superstore/caching.rb
71
72
  - lib/superstore/callbacks.rb
72
73
  - lib/superstore/cassandra_schema.rb
73
74
  - lib/superstore/cassandra_schema/statements.rb
@@ -119,6 +120,7 @@ files:
119
120
  - test/unit/base_test.rb
120
121
  - test/unit/belongs_to/reflection_test.rb
121
122
  - test/unit/belongs_to_test.rb
123
+ - test/unit/caching_test.rb
122
124
  - test/unit/callbacks_test.rb
123
125
  - test/unit/cassandra_schema/statements_test.rb
124
126
  - test/unit/cassandra_schema/tasks_test.rb
@@ -165,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
167
  version: 1.3.5
166
168
  requirements: []
167
169
  rubyforge_project:
168
- rubygems_version: 2.2.1
170
+ rubygems_version: 2.2.2
169
171
  signing_key:
170
172
  specification_version: 4
171
173
  summary: Cassandra ActiveModel