cassanity 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ Not all changes will be here, but the important ones will be for sure.
4
+
5
+ ## 0.2.1
6
+
7
+ * Added [using, order and limit clauses](https://github.com/jnunemaker/cassanity/compare/414d780...3aeb254) to column family select
8
+
9
+ ## 0.2.0
10
+
11
+ *
@@ -1,4 +1,7 @@
1
+ require 'cassanity/argument_generators/using_clause'
1
2
  require 'cassanity/argument_generators/where_clause'
3
+ require 'cassanity/argument_generators/order_clause'
4
+ require 'cassanity/argument_generators/limit_clause'
2
5
 
3
6
  module Cassanity
4
7
  module ArgumentGenerators
@@ -6,7 +9,10 @@ module Cassanity
6
9
 
7
10
  # Internal
8
11
  def initialize(args = {})
12
+ @using_clause = args.fetch(:using_clause) { UsingClause.new }
9
13
  @where_clause = args.fetch(:where_clause) { WhereClause.new }
14
+ @order_clause = args.fetch(:order_clause) { OrderClause.new }
15
+ @limit_clause = args.fetch(:limit_clause) { LimitClause.new }
10
16
  end
11
17
 
12
18
  # Internal
@@ -14,6 +20,9 @@ module Cassanity
14
20
  select = Array(args.fetch(:select, '*'))
15
21
  name = args.fetch(:name)
16
22
  where = args[:where]
23
+ using = args[:using]
24
+ order = args[:order]
25
+ limit = args[:limit]
17
26
 
18
27
  variables = []
19
28
 
@@ -23,10 +32,22 @@ module Cassanity
23
32
 
24
33
  cql = "SELECT #{select.join(', ')} FROM #{name}"
25
34
 
35
+ using_cql, *using_variables = @using_clause.call(using: using)
36
+ cql << using_cql
37
+ variables.concat(using_variables)
38
+
26
39
  where_cql, *where_variables = @where_clause.call(where: where)
27
40
  cql << where_cql
28
41
  variables.concat(where_variables)
29
42
 
43
+ order_cql, *order_variables = @order_clause.call(order: order)
44
+ cql << order_cql
45
+ variables.concat(order_variables)
46
+
47
+ limit_cql, *limit_variables = @limit_clause.call(limit: limit)
48
+ cql << limit_cql
49
+ variables.concat(limit_variables)
50
+
30
51
  [cql, *variables]
31
52
  end
32
53
  end
@@ -0,0 +1,17 @@
1
+ module Cassanity
2
+ module ArgumentGenerators
3
+ class LimitClause
4
+
5
+ # Internal
6
+ def call(args = {})
7
+ limit = args[:limit]
8
+
9
+ if limit.nil?
10
+ ['']
11
+ else
12
+ [" LIMIT #{limit}"]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Cassanity
2
+ module ArgumentGenerators
3
+ class OrderClause
4
+
5
+ # Internal
6
+ def call(args = {})
7
+ order = args[:order]
8
+
9
+ if order.nil? || order.empty?
10
+ ['']
11
+ else
12
+ [" ORDER BY #{order}"]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Cassanity
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -88,16 +88,30 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
88
88
  end
89
89
  end
90
90
 
91
+ context "with using option" do
92
+ let(:using_clause) {
93
+ lambda { |args| [" USING CONSISTENCY BATMAN"]}
94
+ }
95
+
96
+ subject { described_class.new(using_clause: using_clause) }
97
+
98
+ it "returns array of arguments with help from using clause" do
99
+ using = {consistency: :batman}
100
+ cql = "SELECT * FROM #{column_family_name} USING CONSISTENCY BATMAN"
101
+ expected = [cql]
102
+ subject.call({
103
+ name: column_family_name,
104
+ using: using,
105
+ }).should eq(expected)
106
+ end
107
+ end
108
+
91
109
  context "with where option" do
92
110
  let(:where_clause) {
93
111
  lambda { |args| [" WHERE foo = ?", args.fetch(:where).fetch(:foo)]}
94
112
  }
95
113
 
96
- subject {
97
- described_class.new({
98
- where_clause: where_clause,
99
- })
100
- }
114
+ subject { described_class.new(where_clause: where_clause) }
101
115
 
102
116
  it "returns array of arguments with help from where clause" do
103
117
  where = {foo: 'bar'}
@@ -109,5 +123,39 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
109
123
  }).should eq(expected)
110
124
  end
111
125
  end
126
+
127
+ context "with order option" do
128
+ let(:order_clause) {
129
+ lambda { |args| [" ORDER BY #{args.fetch(:order)}"]}
130
+ }
131
+
132
+ subject { described_class.new(order_clause: order_clause) }
133
+
134
+ it "returns array of arguments with help from order clause" do
135
+ cql = "SELECT * FROM #{column_family_name} ORDER BY name"
136
+ expected = [cql]
137
+ subject.call({
138
+ name: column_family_name,
139
+ order: :name,
140
+ }).should eq(expected)
141
+ end
142
+ end
143
+
144
+ context "with limit option" do
145
+ let(:limit_clause) {
146
+ lambda { |args| [" LIMIT #{args.fetch(:limit)}"]}
147
+ }
148
+
149
+ subject { described_class.new(limit_clause: limit_clause) }
150
+
151
+ it "returns array of arguments with help from limit clause" do
152
+ cql = "SELECT * FROM #{column_family_name} LIMIT 50"
153
+ expected = [cql]
154
+ subject.call({
155
+ name: column_family_name,
156
+ limit: 50,
157
+ }).should eq(expected)
158
+ end
159
+ end
112
160
  end
113
161
  end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+ require 'cassanity/argument_generators/limit_clause'
3
+
4
+ describe Cassanity::ArgumentGenerators::LimitClause do
5
+ describe "#call" do
6
+ context "with :limit integer value" do
7
+ it "returns array of arguments" do
8
+ subject.call(limit: 50).should eq([" LIMIT 50"])
9
+ end
10
+ end
11
+
12
+ context "with :limit string value" do
13
+ it "returns array of arguments" do
14
+ subject.call(limit: '50').should eq([" LIMIT 50"])
15
+ end
16
+ end
17
+
18
+ context "with no arguments" do
19
+ it "returns array of arguments where only item is empty string" do
20
+ subject.call.should eq([""])
21
+ end
22
+ end
23
+
24
+ context "with empty arguments" do
25
+ it "returns array of arguments where only item is empty string" do
26
+ subject.call({}).should eq([""])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+ require 'cassanity/argument_generators/order_clause'
3
+
4
+ describe Cassanity::ArgumentGenerators::OrderClause do
5
+ describe "#call" do
6
+ context "with single :order" do
7
+ it "returns array of arguments" do
8
+ subject.call(order: 'name').should eq([" ORDER BY name"])
9
+ end
10
+ end
11
+
12
+ context "with single :order ASC" do
13
+ it "returns array of arguments" do
14
+ subject.call(order: 'name ASC').should eq([" ORDER BY name ASC"])
15
+ end
16
+ end
17
+
18
+ context "with single :order DESC" do
19
+ it "returns array of arguments" do
20
+ subject.call(order: 'name DESC').should eq([" ORDER BY name DESC"])
21
+ end
22
+ end
23
+
24
+ context "with no arguments" do
25
+ it "returns array of arguments where only item is empty string" do
26
+ subject.call.should eq([""])
27
+ end
28
+ end
29
+
30
+ context "with empty arguments" do
31
+ it "returns array of arguments where only item is empty string" do
32
+ subject.call({}).should eq([""])
33
+ end
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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-11-08 00:00:00.000000000 Z
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cassandra-cql
@@ -38,6 +38,7 @@ files:
38
38
  - .gitignore
39
39
  - .rspec
40
40
  - .travis.yml
41
+ - Changelog.md
41
42
  - Gemfile
42
43
  - Guardfile
43
44
  - LICENSE.txt
@@ -64,6 +65,8 @@ files:
64
65
  - lib/cassanity/argument_generators/keyspace_drop.rb
65
66
  - lib/cassanity/argument_generators/keyspace_use.rb
66
67
  - lib/cassanity/argument_generators/keyspaces.rb
68
+ - lib/cassanity/argument_generators/limit_clause.rb
69
+ - lib/cassanity/argument_generators/order_clause.rb
67
70
  - lib/cassanity/argument_generators/set_clause.rb
68
71
  - lib/cassanity/argument_generators/using_clause.rb
69
72
  - lib/cassanity/argument_generators/where_clause.rb
@@ -97,6 +100,8 @@ files:
97
100
  - spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb
98
101
  - spec/unit/cassanity/argument_generators/keyspace_use_spec.rb
99
102
  - spec/unit/cassanity/argument_generators/keyspaces_spec.rb
103
+ - spec/unit/cassanity/argument_generators/limit_clause_spec.rb
104
+ - spec/unit/cassanity/argument_generators/order_clause_spec.rb
100
105
  - spec/unit/cassanity/argument_generators/set_clause_spec.rb
101
106
  - spec/unit/cassanity/argument_generators/using_clause_spec.rb
102
107
  - spec/unit/cassanity/argument_generators/where_clause_spec.rb
@@ -124,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
129
  version: '0'
125
130
  segments:
126
131
  - 0
127
- hash: -3410109094406772154
132
+ hash: -3816618086957989783
128
133
  required_rubygems_version: !ruby/object:Gem::Requirement
129
134
  none: false
130
135
  requirements:
@@ -133,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
138
  version: '0'
134
139
  segments:
135
140
  - 0
136
- hash: -3410109094406772154
141
+ hash: -3816618086957989783
137
142
  requirements: []
138
143
  rubyforge_project:
139
144
  rubygems_version: 1.8.23
@@ -162,6 +167,8 @@ test_files:
162
167
  - spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb
163
168
  - spec/unit/cassanity/argument_generators/keyspace_use_spec.rb
164
169
  - spec/unit/cassanity/argument_generators/keyspaces_spec.rb
170
+ - spec/unit/cassanity/argument_generators/limit_clause_spec.rb
171
+ - spec/unit/cassanity/argument_generators/order_clause_spec.rb
165
172
  - spec/unit/cassanity/argument_generators/set_clause_spec.rb
166
173
  - spec/unit/cassanity/argument_generators/using_clause_spec.rb
167
174
  - spec/unit/cassanity/argument_generators/where_clause_spec.rb