query_builder 0.0.3 → 0.0.4

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: 6be5ac67e82806ac52d166861b2c9d7d4c696d32
4
- data.tar.gz: 91dde9df9536a4a21310070bb9b68f8db4e108f6
3
+ metadata.gz: 314269feed5dfd5be5f4c86914dd836015931c76
4
+ data.tar.gz: 67ce13340d22a8693caa83693f1f4d5d1ca9cfdd
5
5
  SHA512:
6
- metadata.gz: c5fd1cb7c24d527384887feb16211b48658830d38178cb16d678d6ad313337a8877f8afd7f7ffa12c6711cc33e815fbfb08f9982f9e8a4b4622701882cfe3988
7
- data.tar.gz: 904386933c1267e6612e4f9863ada18a728fabe59b509f198553e1a5370fe8200e54b54ec9bde7333f572fe9879e51b293a5371069e8cd6dd2736d11fe75ce60
6
+ metadata.gz: 04410e1ec4f1792a257d776f3951820a035b039725bc7d2e33a0610845c6da895bbbea779465015ad3eb364729fb8ca277c40a67cb04abe0db7a2bb434c0d486
7
+ data.tar.gz: 7d4efce23694c878841a2fefe248a8d2ea11e38a8528e96b6eb11b300cc84e5ed978bde02033681507fb0d37138f1f56a3884a547c395685320b9b27b157e430
@@ -1,3 +1,22 @@
1
+ ## v0.0.4 2015-09-18
2
+
3
+ The (backward-compatible) patch fixes a bug in 'SELECT' statement.
4
+
5
+ ### Bugs Fixed
6
+
7
+ * Fixed 'ORDER BY' condition in 'SELECT' statement (nepalez) with reference to bug report #1 (aq1018)
8
+
9
+ ### Internal
10
+
11
+ * Extracted `Core::Attributes` to the external gem 'attributes_dsl' (nepalez)
12
+
13
+ ### Deleted
14
+
15
+ * `Core::Attributes` (nepalez)
16
+ * `Core::AttributesDSL` (nepalez)
17
+
18
+ [Compare v0.0.3...v0.0.4](https://github.com/nepalez/query_builder/compare/v0.0.3...v0.0.4)
19
+
1
20
  ## v0.0.3 2015-08-21
2
21
 
3
22
  ### Added
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require "attributes_dsl"
3
4
  require "equalizer"
4
5
  require "ice_nine"
5
6
  require "transproc"
@@ -8,8 +8,6 @@ module QueryBuilder
8
8
  #
9
9
  module Core
10
10
 
11
- require_relative "core/attribute_error"
12
- require_relative "core/attribute"
13
11
  require_relative "core/base"
14
12
  require_relative "core/clause"
15
13
  require_relative "core/statement"
@@ -10,55 +10,15 @@ module QueryBuilder::Core
10
10
  #
11
11
  class Base
12
12
 
13
- # @!method attributes
14
- # The hash of default attributes of class' instances
15
- #
16
- # @return [Hash]
17
- #
18
- def self.attributes
19
- @attributes ||= Set.new
20
- end
21
-
22
- # @!method attribute(name, options)
23
- # Declares the attribute with optional default value
24
- #
25
- # @param [Symbol] name The name of the attribute
26
- # @param [Hash] options
27
- # @option options [Object] :default
28
- #
29
- # @return [undefined]
30
- #
31
- def self.attribute(name, options = {})
32
- attributes << Attribute.new(name, options)
33
- define_method(name) { attributes.fetch(name) }
34
- end
35
-
36
- # Makes default attributes inheritable
37
- #
38
- # @private
39
- #
40
- def self.inherited(subclass)
41
- attributes.each do |item|
42
- subclass.public_send(:attribute, *item.arguments)
43
- end
44
- end
45
-
46
- # @!attribute [r] attributes
47
- #
48
- # @return [Hash] The hash of the initialized attributes
49
- #
50
- attr_reader :attributes
13
+ extend AttributesDSL
51
14
 
52
15
  # @!method initialize(attributes = {})
53
16
  # Initializes the instance
54
17
  #
55
18
  # @param [Hash] attributes The custom attributes of the instance
56
19
  #
57
- def initialize(attributes = {})
58
- validate_unknown attributes
59
- validate_missing attributes
60
-
61
- @attributes = default_attributes.merge(attributes)
20
+ def initialize(_attributes = {})
21
+ super
62
22
  IceNine.deep_freeze(self)
63
23
  end
64
24
 
@@ -73,30 +33,6 @@ module QueryBuilder::Core
73
33
  ""
74
34
  end
75
35
 
76
- private
77
-
78
- def known_attributes
79
- self.class.attributes
80
- end
81
-
82
- def required_attributes
83
- known_attributes.select(&:required)
84
- end
85
-
86
- def default_attributes
87
- known_attributes.each_with_object({}) { |e, a| a[e.name] = e.default }
88
- end
89
-
90
- def validate_unknown(hash)
91
- unknown = hash.keys - known_attributes.map(&:name)
92
- fail AttributeError.new(:unknown, unknown) if unknown.any?
93
- end
94
-
95
- def validate_missing(hash)
96
- missed = required_attributes.map(&:name) - hash.keys
97
- fail AttributeError.new(:missed, missed) if missed.any?
98
- end
99
-
100
36
  end # class Base
101
37
 
102
38
  end # module CQLBuiler::Core
@@ -38,7 +38,7 @@ module QueryBuilder::CQL
38
38
 
39
39
  # @private
40
40
  def to_s
41
- "ORDER BY (#{name} #{desc ? "DESC" : "ASC"})"
41
+ "ORDER BY #{name} #{desc ? "DESC" : "ASC"}"
42
42
  end
43
43
 
44
44
  end # class Clause
@@ -4,6 +4,6 @@ module QueryBuilder
4
4
 
5
5
  # The semantic version of the module.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.0.3".freeze
7
+ VERSION = "0.0.4".freeze
8
8
 
9
9
  end # module QueryBuilder
@@ -22,9 +22,10 @@ Gem::Specification.new do |gem|
22
22
 
23
23
  gem.required_ruby_version = ">= 1.9.3"
24
24
 
25
- gem.add_runtime_dependency "transproc", "~> 0.3"
25
+ gem.add_runtime_dependency "attributes_dsl", "~> 0.0"
26
26
  gem.add_runtime_dependency "equalizer", "~> 0.0.11"
27
27
  gem.add_runtime_dependency "ice_nine", "~> 0.11"
28
+ gem.add_runtime_dependency "transproc", "~> 0.3"
28
29
 
29
30
  gem.add_development_dependency "hexx-rspec", "~> 0.5"
30
31
 
@@ -40,7 +40,7 @@ describe "SELECT" do
40
40
  .allow_filtering
41
41
  end
42
42
 
43
- let(:cql) { "SELECT DISTINCT uuid AS id, name FROM wildlife.species WHERE id >= 3 AND id < 10 AND area IN ('park', 'garden') AND names[1] = 'cat' ORDER BY (name DESC) LIMIT 10 ALLOW FILTERING;" }
43
+ let(:cql) { "SELECT DISTINCT uuid AS id, name FROM wildlife.species WHERE id >= 3 AND id < 10 AND area IN ('park', 'garden') AND names[1] = 'cat' ORDER BY name DESC LIMIT 10 ALLOW FILTERING;" }
44
44
  end
45
45
 
46
46
  end # describe SELECT
@@ -2,105 +2,36 @@
2
2
 
3
3
  describe QueryBuilder::Core::Base do
4
4
 
5
- let(:exception) { QueryBuilder::Core::AttributeError }
6
- let(:klass) { Class.new(described_class) }
7
- let(:instance) { klass.new(attributes) }
8
- let(:attributes) { { foo: :FOO } }
5
+ let(:klass) { Class.new(described_class) { attribute :foo } }
9
6
 
10
- describe ".attribute" do
11
- shared_examples :adding_attribute do
12
- it "updates .attributes" do
13
- expect { subject }
14
- .to change { klass.attributes.map(&:name) }
15
- .from([])
16
- .to([:foo])
17
- end
18
-
19
- it "adds key to the #attributes" do
20
- expect { subject }
21
- .to change { klass.new.attributes }
22
- .from({})
23
- .to(foo: default)
7
+ describe ".new" do
8
+ shared_examples :object_constructor do
9
+ it "[is immutable]" do
10
+ expect(subject).to be_frozen
24
11
  end
25
12
 
26
- it "defines the instance method" do
27
- expect { subject }
28
- .to change { klass.instance_methods }
29
- .by [:foo]
13
+ it "[doesn't freeze attributes]" do
14
+ expect { subject }.not_to change { attributes.frozen? }
30
15
  end
31
16
 
32
- it "makes the method to return the attribute" do
33
- subject
34
- expect(klass.new.foo).to eql(default)
35
- expect(klass.new(foo: :FOO).foo).to eql(:FOO)
17
+ it "[initializes #attributes]" do
18
+ expect(subject.attributes).to eql attributes
36
19
  end
37
- end # shared examples
38
-
39
- it_behaves_like :adding_attribute do
40
- subject { klass.attribute :foo }
41
- let(:default) { nil }
42
- end
43
-
44
- it_behaves_like :adding_attribute do
45
- subject { klass.attribute :foo, default: default }
46
- let(:default) { :Foo }
47
20
  end
48
- end # describe .attributes
49
21
 
50
- describe ".inherited" do
51
- subject { Class.new(klass).attributes.map(&:name) }
52
-
53
- let(:klass) do
54
- Class.new(described_class) { attribute :foo, default: :FOO }
55
- end
56
-
57
- it "inherits the default attibutes of parent class" do
58
- expect(subject).to eql [:foo]
22
+ it_behaves_like :object_constructor do
23
+ subject { klass.new(attributes) }
24
+ let(:attributes) { { foo: :FOO } }
59
25
  end
60
- end # describe .inherited
61
-
62
- describe ".new" do
63
- subject { instance }
64
-
65
- before { klass.attribute :foo, required: true }
66
26
 
67
- it "is immutable" do
68
- expect(subject).to be_frozen
69
- end
70
-
71
- it "doesn't freeze attributes" do
72
- expect { subject }.not_to change { attributes.frozen? }
73
- end
74
-
75
- context "with unknown attribute" do
76
- let(:attributes) { { foo: :FOO, bar: :BAR } }
77
-
78
- it "raises AttributeError" do
79
- expect { subject }.to raise_error do |error|
80
- expect(error).to be_kind_of exception
81
- expect(error.message).to include "unknown "
82
- expect(error.message).to include "bar"
83
- end
84
- end
85
- end
86
-
87
- context "with missed attribute" do
88
- before { klass.attribute :bar, required: true }
89
-
90
- it "raises AttributeError" do
91
- expect { subject }.to raise_error do |error|
92
- expect(error).to be_kind_of exception
93
- expect(error.message).to include "missed "
94
- expect(error.message).to include "bar"
95
- end
96
- end
27
+ it_behaves_like :object_constructor do
28
+ subject { klass.new }
29
+ let(:attributes) { { foo: nil } }
97
30
  end
98
31
  end # describe .new
99
32
 
100
33
  describe "#to_s" do
101
- subject { instance.to_s }
102
-
103
- let(:klass) { Class.new(described_class) { attribute :foo } }
34
+ subject { klass.new.to_s }
104
35
 
105
36
  it "returns empty string" do
106
37
  expect(subject).to eql("")
@@ -71,6 +71,10 @@ describe QueryBuilder::Core::Statement do
71
71
  context "new clause" do
72
72
  subject { statement << qux }
73
73
 
74
+ it "preserves attributes" do
75
+ expect(subject.attributes).to eql(statement.attributes)
76
+ end
77
+
74
78
  it "adds the clause" do
75
79
  expect(subject.clauses).to eql %w(bar baz qux)
76
80
  end
@@ -79,6 +83,10 @@ describe QueryBuilder::Core::Statement do
79
83
  context "existing clause" do
80
84
  subject { statement << bar }
81
85
 
86
+ it "preserves attributes" do
87
+ expect(subject.attributes).to eql(statement.attributes)
88
+ end
89
+
82
90
  it "rewrites the clause" do
83
91
  expect(subject.clauses).to eql %w(baz bar)
84
92
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-23 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: transproc
14
+ name: attributes_dsl
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
19
+ version: '0.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.3'
26
+ version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: equalizer
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: transproc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: hexx-rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -101,8 +115,6 @@ files:
101
115
  - config/metrics/yardstick.yml
102
116
  - lib/query_builder.rb
103
117
  - lib/query_builder/core.rb
104
- - lib/query_builder/core/attribute.rb
105
- - lib/query_builder/core/attribute_error.rb
106
118
  - lib/query_builder/core/base.rb
107
119
  - lib/query_builder/core/clause.rb
108
120
  - lib/query_builder/core/statement.rb
@@ -272,8 +284,6 @@ files:
272
284
  - spec/integration/update_spec.rb
273
285
  - spec/integration/use_spec.rb
274
286
  - spec/spec_helper.rb
275
- - spec/unit/core/attribute_error_spec.rb
276
- - spec/unit/core/attribute_spec.rb
277
287
  - spec/unit/core/base_spec.rb
278
288
  - spec/unit/core/clause_spec.rb
279
289
  - spec/unit/core/statement_spec.rb
@@ -322,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
332
  version: '0'
323
333
  requirements: []
324
334
  rubyforge_project:
325
- rubygems_version: 2.4.6
335
+ rubygems_version: 2.4.8
326
336
  signing_key:
327
337
  specification_version: 4
328
338
  summary: Builder of the CQL statements.
@@ -369,8 +379,6 @@ test_files:
369
379
  - spec/integration/update_spec.rb
370
380
  - spec/integration/use_spec.rb
371
381
  - spec/spec_helper.rb
372
- - spec/unit/core/attribute_error_spec.rb
373
- - spec/unit/core/attribute_spec.rb
374
382
  - spec/unit/core/base_spec.rb
375
383
  - spec/unit/core/clause_spec.rb
376
384
  - spec/unit/core/statement_spec.rb
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module QueryBuilder::Core
4
-
5
- # Describes the attribute of AST node
6
- #
7
- class Attribute
8
-
9
- include Equalizer.new(:name)
10
-
11
- # @!attribute [r] name
12
- #
13
- # @return [Symbol] The name of the attribute
14
- #
15
- attr_reader :name
16
-
17
- # @!attribute [r] default
18
- #
19
- # @return [Object] The default value for the attribute
20
- #
21
- attr_reader :default
22
-
23
- # @!attribute [r] required
24
- #
25
- # @return [Boolean] Whether the attribute is required or not
26
- #
27
- attr_reader :required
28
-
29
- # Initializes the attribute with name and options
30
- #
31
- # @param [Symbol] name
32
- # @param [Hash] options
33
- # @option options [Object] :default The default value for the attribute
34
- # @option options [Boolean] :required Whether the attribute is required
35
- #
36
- def initialize(name, options = {})
37
- @name = name
38
- @default = options[:default]
39
- @required = options.fetch(:required) { false }
40
-
41
- IceNine.deep_freeze(self)
42
- end
43
-
44
- # Returns arguments of the attribute initializer
45
- #
46
- # @return [Array]
47
- #
48
- def arguments
49
- [name, default: default, required: required]
50
- end
51
-
52
- end # class Attribute
53
-
54
- end # module QueryBuilder::Core
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module QueryBuilder::Core
4
-
5
- # The exception to be raised by AST nodes' initializers
6
- #
7
- class AttributeError < KeyError
8
-
9
- # Initializes the error with problem definition and the list of attributes
10
- #
11
- # @param [#to_s] problem
12
- # @param [Array<#to_s>] list
13
- #
14
- def initialize(problem, list)
15
- super [
16
- "#{problem} attribute",
17
- (list.one? ? ": " : "s: "),
18
- list.map { |item| ":#{item}" }.join(", ")
19
- ].join
20
- IceNine.deep_freeze(self)
21
- end
22
-
23
- end # class UndefinedAttributeError
24
-
25
- end # module QueryBuilder::Core
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe QueryBuilder::Core::AttributeError do
4
-
5
- let(:error) { described_class.new(:missed, attributes) }
6
- let(:attributes) { [:foo] }
7
-
8
- describe ".new" do
9
- subject { error }
10
-
11
- it "is a KeyError" do
12
- expect(error).to be_kind_of KeyError
13
- end
14
-
15
- it "is immutable" do
16
- expect(error).to be_frozen
17
- end
18
- end # describe .new
19
-
20
- describe "#message" do
21
- subject { error.message }
22
-
23
- context "with one attribute" do
24
- it "returns proper text" do
25
- expect(subject).to eql "missed attribute: :foo"
26
- end
27
- end # context
28
-
29
- context "with many attributes" do
30
- let(:attributes) { [:foo, :bar] }
31
-
32
- it "returns proper text" do
33
- expect(subject).to eql "missed attributes: :foo, :bar"
34
- end
35
- end # context
36
- end # describe #message
37
-
38
- end # describe QueryBuilder::Core::AttributeError
@@ -1,70 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe QueryBuilder::Core::Attribute do
4
-
5
- let(:attribute) { described_class.new :foo }
6
-
7
- describe ".new" do
8
- subject { attribute }
9
-
10
- it "is immutable" do
11
- expect(subject).to be_frozen
12
- end
13
- end # describe .new
14
-
15
- describe "#arguments" do
16
- subject { attribute.arguments }
17
-
18
- let(:arguments) { [:foo, default: :FOO, required: true] }
19
- let(:attribute) { described_class.new(*arguments) }
20
-
21
- it "returns argumens of the initializer" do
22
- expect(subject).to eql(arguments)
23
- end
24
- end # describe #arguments
25
-
26
- describe "#name" do
27
- subject { attribute.name }
28
-
29
- it "is initialized" do
30
- expect(subject).to eql(:foo)
31
- end
32
- end # describe #name
33
-
34
- describe "#default" do
35
- subject { attribute.default }
36
-
37
- context "by default" do
38
- it "returns nil" do
39
- expect(subject).to be_nil
40
- end
41
- end # context
42
-
43
- context "when value is set" do
44
- let(:attribute) { described_class.new :foo, default: :FOO }
45
-
46
- it "is initialized" do
47
- expect(subject).to eql(:FOO)
48
- end
49
- end # context
50
- end # describe #default
51
-
52
- describe "#required" do
53
- subject { attribute.required }
54
-
55
- context "by default" do
56
- it "returns false" do
57
- expect(subject).to eql(false)
58
- end
59
- end # context
60
-
61
- context "when value is set" do
62
- let(:attribute) { described_class.new :foo, required: true }
63
-
64
- it "is initialized" do
65
- expect(subject).to eql(true)
66
- end
67
- end # context
68
- end # describe #required
69
-
70
- end # describe QueryBuilder::Core::Attribute