query_builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +9 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -0
  7. data/.travis.yml +25 -0
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +5 -0
  10. data/Gemfile +7 -0
  11. data/Guardfile +14 -0
  12. data/LICENSE +21 -0
  13. data/README.md +95 -0
  14. data/Rakefile +34 -0
  15. data/config/metrics/STYLEGUIDE +230 -0
  16. data/config/metrics/cane.yml +5 -0
  17. data/config/metrics/churn.yml +6 -0
  18. data/config/metrics/flay.yml +2 -0
  19. data/config/metrics/metric_fu.yml +14 -0
  20. data/config/metrics/reek.yml +1 -0
  21. data/config/metrics/roodi.yml +24 -0
  22. data/config/metrics/rubocop.yml +80 -0
  23. data/config/metrics/saikuro.yml +3 -0
  24. data/config/metrics/simplecov.yml +6 -0
  25. data/config/metrics/yardstick.yml +37 -0
  26. data/lib/query_builder.rb +9 -0
  27. data/lib/query_builder/core.rb +19 -0
  28. data/lib/query_builder/core/attribute.rb +54 -0
  29. data/lib/query_builder/core/attribute_error.rb +25 -0
  30. data/lib/query_builder/core/base.rb +102 -0
  31. data/lib/query_builder/core/clause.rb +46 -0
  32. data/lib/query_builder/core/statement.rb +55 -0
  33. data/lib/query_builder/cql.rb +80 -0
  34. data/lib/query_builder/cql/contexts.rb +21 -0
  35. data/lib/query_builder/cql/contexts/aggregate.rb +42 -0
  36. data/lib/query_builder/cql/contexts/column.rb +59 -0
  37. data/lib/query_builder/cql/contexts/field.rb +48 -0
  38. data/lib/query_builder/cql/contexts/function.rb +46 -0
  39. data/lib/query_builder/cql/contexts/index.rb +44 -0
  40. data/lib/query_builder/cql/contexts/keyspace.rb +107 -0
  41. data/lib/query_builder/cql/contexts/permission.rb +59 -0
  42. data/lib/query_builder/cql/contexts/role.rb +51 -0
  43. data/lib/query_builder/cql/contexts/table.rb +140 -0
  44. data/lib/query_builder/cql/contexts/trigger.rb +42 -0
  45. data/lib/query_builder/cql/contexts/type.rb +52 -0
  46. data/lib/query_builder/cql/contexts/user.rb +53 -0
  47. data/lib/query_builder/cql/modifiers.rb +61 -0
  48. data/lib/query_builder/cql/modifiers/add_column.rb +50 -0
  49. data/lib/query_builder/cql/modifiers/add_field.rb +49 -0
  50. data/lib/query_builder/cql/modifiers/allow_filtering.rb +45 -0
  51. data/lib/query_builder/cql/modifiers/alter.rb +44 -0
  52. data/lib/query_builder/cql/modifiers/called_on_null.rb +47 -0
  53. data/lib/query_builder/cql/modifiers/clustering_order.rb +51 -0
  54. data/lib/query_builder/cql/modifiers/column.rb +59 -0
  55. data/lib/query_builder/cql/modifiers/compact_storage.rb +46 -0
  56. data/lib/query_builder/cql/modifiers/count.rb +47 -0
  57. data/lib/query_builder/cql/modifiers/counter.rb +45 -0
  58. data/lib/query_builder/cql/modifiers/delete.rb +48 -0
  59. data/lib/query_builder/cql/modifiers/distinct.rb +45 -0
  60. data/lib/query_builder/cql/modifiers/finalfunc.rb +47 -0
  61. data/lib/query_builder/cql/modifiers/if.rb +44 -0
  62. data/lib/query_builder/cql/modifiers/if_exists.rb +46 -0
  63. data/lib/query_builder/cql/modifiers/if_not_exists.rb +46 -0
  64. data/lib/query_builder/cql/modifiers/initcond.rb +49 -0
  65. data/lib/query_builder/cql/modifiers/insert.rb +68 -0
  66. data/lib/query_builder/cql/modifiers/limit.rb +49 -0
  67. data/lib/query_builder/cql/modifiers/norecursive.rb +45 -0
  68. data/lib/query_builder/cql/modifiers/or_replace.rb +44 -0
  69. data/lib/query_builder/cql/modifiers/order.rb +50 -0
  70. data/lib/query_builder/cql/modifiers/password.rb +49 -0
  71. data/lib/query_builder/cql/modifiers/primary_key.rb +51 -0
  72. data/lib/query_builder/cql/modifiers/returns.rb +49 -0
  73. data/lib/query_builder/cql/modifiers/selected.rb +54 -0
  74. data/lib/query_builder/cql/modifiers/sfunc.rb +47 -0
  75. data/lib/query_builder/cql/modifiers/statement.rb +47 -0
  76. data/lib/query_builder/cql/modifiers/stype.rb +47 -0
  77. data/lib/query_builder/cql/modifiers/superuser.rb +54 -0
  78. data/lib/query_builder/cql/modifiers/timestamp.rb +50 -0
  79. data/lib/query_builder/cql/modifiers/unlogged.rb +45 -0
  80. data/lib/query_builder/cql/modifiers/update.rb +44 -0
  81. data/lib/query_builder/cql/modifiers/using.rb +48 -0
  82. data/lib/query_builder/cql/modifiers/using_options.rb +51 -0
  83. data/lib/query_builder/cql/modifiers/where.rb +44 -0
  84. data/lib/query_builder/cql/modifiers/where_clustered.rb +51 -0
  85. data/lib/query_builder/cql/modifiers/with.rb +44 -0
  86. data/lib/query_builder/cql/modifiers/with_options.rb +42 -0
  87. data/lib/query_builder/cql/operators.rb +29 -0
  88. data/lib/query_builder/cql/operators/cql.rb +23 -0
  89. data/lib/query_builder/cql/operators/cql_composite.rb +20 -0
  90. data/lib/query_builder/cql/operators/cql_dec.rb +21 -0
  91. data/lib/query_builder/cql/operators/cql_element.rb +23 -0
  92. data/lib/query_builder/cql/operators/cql_entries.rb +20 -0
  93. data/lib/query_builder/cql/operators/cql_frozen.rb +20 -0
  94. data/lib/query_builder/cql/operators/cql_full.rb +20 -0
  95. data/lib/query_builder/cql/operators/cql_gt.rb +23 -0
  96. data/lib/query_builder/cql/operators/cql_gte.rb +23 -0
  97. data/lib/query_builder/cql/operators/cql_in.rb +23 -0
  98. data/lib/query_builder/cql/operators/cql_inc.rb +21 -0
  99. data/lib/query_builder/cql/operators/cql_keys.rb +20 -0
  100. data/lib/query_builder/cql/operators/cql_list.rb +21 -0
  101. data/lib/query_builder/cql/operators/cql_literal.rb +84 -0
  102. data/lib/query_builder/cql/operators/cql_lt.rb +23 -0
  103. data/lib/query_builder/cql/operators/cql_lte.rb +23 -0
  104. data/lib/query_builder/cql/operators/cql_map.rb +25 -0
  105. data/lib/query_builder/cql/operators/cql_set.rb +21 -0
  106. data/lib/query_builder/cql/operators/cql_token.rb +21 -0
  107. data/lib/query_builder/cql/operators/cql_token_value.rb +23 -0
  108. data/lib/query_builder/cql/operators/cql_ttl.rb +20 -0
  109. data/lib/query_builder/cql/operators/cql_tuple.rb +21 -0
  110. data/lib/query_builder/cql/operators/cql_tuple_value.rb +23 -0
  111. data/lib/query_builder/cql/operators/cql_writetime.rb +20 -0
  112. data/lib/query_builder/cql/statements.rb +25 -0
  113. data/lib/query_builder/cql/statements/alter_column.rb +27 -0
  114. data/lib/query_builder/cql/statements/alter_field.rb +27 -0
  115. data/lib/query_builder/cql/statements/alter_keyspace.rb +25 -0
  116. data/lib/query_builder/cql/statements/alter_role.rb +26 -0
  117. data/lib/query_builder/cql/statements/alter_table.rb +25 -0
  118. data/lib/query_builder/cql/statements/alter_user.rb +26 -0
  119. data/lib/query_builder/cql/statements/batch.rb +31 -0
  120. data/lib/query_builder/cql/statements/create_aggregate.rb +36 -0
  121. data/lib/query_builder/cql/statements/create_column.rb +35 -0
  122. data/lib/query_builder/cql/statements/create_field.rb +25 -0
  123. data/lib/query_builder/cql/statements/create_function.rb +38 -0
  124. data/lib/query_builder/cql/statements/create_index.rb +41 -0
  125. data/lib/query_builder/cql/statements/create_keyspace.rb +26 -0
  126. data/lib/query_builder/cql/statements/create_role.rb +26 -0
  127. data/lib/query_builder/cql/statements/create_table.rb +30 -0
  128. data/lib/query_builder/cql/statements/create_trigger.rb +29 -0
  129. data/lib/query_builder/cql/statements/create_type.rb +26 -0
  130. data/lib/query_builder/cql/statements/create_user.rb +27 -0
  131. data/lib/query_builder/cql/statements/delete.rb +32 -0
  132. data/lib/query_builder/cql/statements/drop_aggregate.rb +25 -0
  133. data/lib/query_builder/cql/statements/drop_column.rb +23 -0
  134. data/lib/query_builder/cql/statements/drop_function.rb +25 -0
  135. data/lib/query_builder/cql/statements/drop_index.rb +25 -0
  136. data/lib/query_builder/cql/statements/drop_keyspace.rb +25 -0
  137. data/lib/query_builder/cql/statements/drop_role.rb +25 -0
  138. data/lib/query_builder/cql/statements/drop_table.rb +25 -0
  139. data/lib/query_builder/cql/statements/drop_trigger.rb +25 -0
  140. data/lib/query_builder/cql/statements/drop_type.rb +25 -0
  141. data/lib/query_builder/cql/statements/drop_user.rb +25 -0
  142. data/lib/query_builder/cql/statements/grant.rb +31 -0
  143. data/lib/query_builder/cql/statements/insert.rb +27 -0
  144. data/lib/query_builder/cql/statements/list_permissions.rb +35 -0
  145. data/lib/query_builder/cql/statements/list_roles.rb +23 -0
  146. data/lib/query_builder/cql/statements/list_users.rb +23 -0
  147. data/lib/query_builder/cql/statements/rename_column.rb +27 -0
  148. data/lib/query_builder/cql/statements/rename_field.rb +25 -0
  149. data/lib/query_builder/cql/statements/revoke.rb +31 -0
  150. data/lib/query_builder/cql/statements/select.rb +35 -0
  151. data/lib/query_builder/cql/statements/truncate.rb +23 -0
  152. data/lib/query_builder/cql/statements/update.rb +31 -0
  153. data/lib/query_builder/cql/statements/use.rb +23 -0
  154. data/lib/query_builder/rspec.rb +25 -0
  155. data/lib/query_builder/version.rb +9 -0
  156. data/query_builder.gemspec +31 -0
  157. data/spec/integration/alter_keyspace_spec.rb +17 -0
  158. data/spec/integration/alter_role_spec.rb +28 -0
  159. data/spec/integration/alter_table_add_spec.rb +21 -0
  160. data/spec/integration/alter_table_alter_spec.rb +15 -0
  161. data/spec/integration/alter_table_drop_spec.rb +15 -0
  162. data/spec/integration/alter_table_rename_spec.rb +15 -0
  163. data/spec/integration/alter_table_with_spec.rb +17 -0
  164. data/spec/integration/alter_type_add_spec.rb +15 -0
  165. data/spec/integration/alter_type_alter_spec.rb +15 -0
  166. data/spec/integration/alter_type_rename_spec.rb +15 -0
  167. data/spec/integration/alter_user_spec.rb +28 -0
  168. data/spec/integration/batch_spec.rb +32 -0
  169. data/spec/integration/create_aggregate_spec.rb +31 -0
  170. data/spec/integration/create_function_spec.rb +29 -0
  171. data/spec/integration/create_index_spec.rb +35 -0
  172. data/spec/integration/create_keyspace_spec.rb +24 -0
  173. data/spec/integration/create_role_spec.rb +26 -0
  174. data/spec/integration/create_table_spec.rb +34 -0
  175. data/spec/integration/create_trigger_spec.rb +21 -0
  176. data/spec/integration/create_type_spec.rb +20 -0
  177. data/spec/integration/create_user_spec.rb +23 -0
  178. data/spec/integration/delete_spec.rb +28 -0
  179. data/spec/integration/drop_aggregate_spec.rb +21 -0
  180. data/spec/integration/drop_function_spec.rb +21 -0
  181. data/spec/integration/drop_index_spec.rb +21 -0
  182. data/spec/integration/drop_keyspace_spec.rb +18 -0
  183. data/spec/integration/drop_role_spec.rb +18 -0
  184. data/spec/integration/drop_table_spec.rb +18 -0
  185. data/spec/integration/drop_trigger_spec.rb +21 -0
  186. data/spec/integration/drop_type_spec.rb +18 -0
  187. data/spec/integration/drop_user_spec.rb +18 -0
  188. data/spec/integration/grant_spec.rb +29 -0
  189. data/spec/integration/insert_spec.rb +22 -0
  190. data/spec/integration/list_permissions_spec.rb +34 -0
  191. data/spec/integration/list_roles_spec.rb +12 -0
  192. data/spec/integration/list_users_spec.rb +12 -0
  193. data/spec/integration/revoke_spec.rb +29 -0
  194. data/spec/integration/select_spec.rb +46 -0
  195. data/spec/integration/truncate_spec.rb +12 -0
  196. data/spec/integration/update_spec.rb +23 -0
  197. data/spec/integration/use_spec.rb +12 -0
  198. data/spec/spec_helper.rb +16 -0
  199. data/spec/unit/core/attribute_error_spec.rb +38 -0
  200. data/spec/unit/core/attribute_spec.rb +70 -0
  201. data/spec/unit/core/base_spec.rb +110 -0
  202. data/spec/unit/core/clause_spec.rb +101 -0
  203. data/spec/unit/core/statement_spec.rb +88 -0
  204. data/spec/unit/cql/operators/cql_composite_spec.rb +12 -0
  205. data/spec/unit/cql/operators/cql_dec_spec.rb +12 -0
  206. data/spec/unit/cql/operators/cql_element_spec.rb +12 -0
  207. data/spec/unit/cql/operators/cql_entries_spec.rb +12 -0
  208. data/spec/unit/cql/operators/cql_frozen_spec.rb +12 -0
  209. data/spec/unit/cql/operators/cql_full_spec.rb +12 -0
  210. data/spec/unit/cql/operators/cql_gt_spec.rb +19 -0
  211. data/spec/unit/cql/operators/cql_gte_spec.rb +19 -0
  212. data/spec/unit/cql/operators/cql_in_spec.rb +12 -0
  213. data/spec/unit/cql/operators/cql_inc_spec.rb +12 -0
  214. data/spec/unit/cql/operators/cql_keys_spec.rb +12 -0
  215. data/spec/unit/cql/operators/cql_list_spec.rb +12 -0
  216. data/spec/unit/cql/operators/cql_literal_spec.rb +83 -0
  217. data/spec/unit/cql/operators/cql_lt_spec.rb +19 -0
  218. data/spec/unit/cql/operators/cql_lte_spec.rb +19 -0
  219. data/spec/unit/cql/operators/cql_map_spec.rb +12 -0
  220. data/spec/unit/cql/operators/cql_set_spec.rb +12 -0
  221. data/spec/unit/cql/operators/cql_spec.rb +12 -0
  222. data/spec/unit/cql/operators/cql_token_spec.rb +12 -0
  223. data/spec/unit/cql/operators/cql_token_value_spec.rb +12 -0
  224. data/spec/unit/cql/operators/cql_ttl_spec.rb +12 -0
  225. data/spec/unit/cql/operators/cql_tuple_spec.rb +12 -0
  226. data/spec/unit/cql/operators/cql_tuple_value_spec.rb +12 -0
  227. data/spec/unit/cql/operators/cql_writetime_spec.rb +12 -0
  228. data/spec/unit/cql/operators_spec.rb +66 -0
  229. metadata +405 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45ec7981eb5da1820500a5873680a201875e5100
4
+ data.tar.gz: b8a336def92119081a5a6ed012e3d2673d9dcf3c
5
+ SHA512:
6
+ metadata.gz: 123bffe7fba817827f329e8f9e4a041e7534f981e5dcf0ac2291b4cbb45f99e357fe9487220baa36988ded868e3f91d5e37435173f45344d44ea0b9fabae0860
7
+ data.tar.gz: 76b109e5845859e337b7602fa78fab9267b955106ad2df82b76fe9c036067f8ac1424fbceb31e8dd8f802f7fef6b59a3f18e9100246b5ba4c454501a774e5201
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ *.lock
3
+ .bundle/
4
+ .yardoc/
5
+ coverage/
6
+ doc/
7
+ log/
8
+ pkg/
9
+ tmp/
data/.metrics ADDED
@@ -0,0 +1,9 @@
1
+ # Settings for metric_fu and its packages are collected in the `config/metrics`
2
+ # and loaded by the Hexx::Suit::Metrics::MetricFu.
3
+
4
+ begin
5
+ require "hexx-suit"
6
+ Hexx::Suit::Metrics::MetricFu.load
7
+ rescue LoadError
8
+ puts "The 'hexx-suit' gem is not installed"
9
+ end
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ inherit_from: "./config/metrics/rubocop.yml"
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ language: ruby
3
+ sudo: false
4
+ cache: bundler
5
+ bundler_args: --without metrics
6
+ script: bundle exec rake test:coverage:run
7
+ env:
8
+ global:
9
+ - JRUBY_OPTS="-Xcli.debug=true --debug"
10
+ rvm:
11
+ - '1.9.3'
12
+ - '2.0'
13
+ - '2.1'
14
+ - '2.2'
15
+ - ruby-head
16
+ - rbx-2 --1.9
17
+ - rbx-2 --2.1
18
+ - jruby-1.7-19mode
19
+ - jruby-1.7-21mode
20
+ - jruby-9.0.0.0
21
+ - jruby-head
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - rvm: jruby-head
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --asset LICENSE
2
+ --exclude lib/query_builder/version.rb
3
+ --output doc/api
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## v0.0.1 2015-08-20
2
+
3
+ First release
4
+
5
+ [Compare Initial...v0.0.1](https://github.com/nepalez/query_builder/compare/Initial...v0.0.1)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :metrics do
6
+ gem "hexx-suit", "~> 2.3" if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.2"
7
+ end
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ guard :rspec, cmd: "bundle exec rspec" do
4
+
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+
7
+ watch(%r{^lib/query_builder/(.+)\.rb}) do |m|
8
+ "spec/unit/#{m[1]}_spec.rb"
9
+ end
10
+
11
+ watch("lib/query_builder.rb") { "spec/integration" }
12
+ watch("spec/spec_helper.rb") { "spec" }
13
+
14
+ end # guard :rspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2015 Andrew Kozin (nepalez), andrew.kozin@gmail.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ QueryBuilder
2
+ ============
3
+
4
+ [![Gem Version](https://img.shields.io/gem/v/query_builder.svg?style=flat)][gem]
5
+ [![Build Status](https://img.shields.io/travis/nepalez/query_builder/master.svg?style=flat)][travis]
6
+ [![Dependency Status](https://img.shields.io/gemnasium/nepalez/query_builder.svg?style=flat)][gemnasium]
7
+ [![Code Climate](https://img.shields.io/codeclimate/github/nepalez/query_builder.svg?style=flat)][codeclimate]
8
+ [![Coverage](https://img.shields.io/coveralls/nepalez/query_builder.svg?style=flat)][coveralls]
9
+ [![Inline docs](http://inch-ci.org/github/nepalez/query_builder.svg)][inch]
10
+
11
+ [codeclimate]: https://codeclimate.com/github/nepalez/query_builder
12
+ [coveralls]: https://coveralls.io/r/nepalez/query_builder
13
+ [gem]: https://rubygems.org/gems/query_builder
14
+ [gemnasium]: https://gemnasium.com/nepalez/query_builder
15
+ [travis]: https://travis-ci.org/nepalez/query_builder
16
+ [inch]: https://inch-ci.org/github/nepalez/query_builder
17
+
18
+ Builder of [CQL 3](https://cassandra.apache.org/doc/cql3/CQL.html#CassandraQueryLanguageCQLv3.2.0) (Cassandra Query Language) statements in OOP style.
19
+
20
+ Synopsis
21
+ --------
22
+
23
+ ```ruby
24
+ require "query_builder"
25
+
26
+ include QueryBuilder::CQL::Operators # for operators like cql_gt, cql_lte below.
27
+
28
+ table = QueryBuilder::CQL.keyspace(:auth).table(:users)
29
+
30
+ statement = table
31
+ .select(:id, :role)
32
+ .select(name: :user)
33
+ .where(id: cql_gt(1))
34
+ .where(id: cql_lte(4))
35
+ .using(consistency: :quorum)
36
+ .limit(3)
37
+ # => #<QueryBuilder::CQL::Statements::Select ...>
38
+
39
+ statement.to_s
40
+ # => "SELECT id, role, user AS name FROM auth.users WHERE id > 1 AND id <= 4 USING consistency = 'quorum' LIMIT 3;"
41
+ ```
42
+
43
+ See the **[list of all supported contexts, statements and operators](https://github.com/nepalez/query_builder/wiki)**.
44
+
45
+ The gem doesn't depend on any specific Cassandra driver. It could be used to extend [official Datastax driver](https://github.com/datastax/ruby-driver) with features of CQL building.
46
+
47
+ It doesn't validate CQL statements, leaving this to either driver or Cassandra database.
48
+
49
+ Installation
50
+ ------------
51
+
52
+ Add this line to your application's Gemfile:
53
+
54
+ ```ruby
55
+ # Gemfile
56
+ gem "query_builder"
57
+ ```
58
+
59
+ Then execute:
60
+
61
+ ```
62
+ bundle
63
+ ```
64
+
65
+ Or add it manually:
66
+
67
+ ```
68
+ gem install query_builder
69
+ ```
70
+
71
+ Compatibility
72
+ -------------
73
+
74
+ Tested under rubies [compatible to MRI 1.9.3+](.travis.yml).
75
+
76
+ Uses [RSpec] 3.0+ for testing and [hexx-suit] for dev/test tools collection.
77
+
78
+ [RSpec]: http://rspec.org
79
+ [hexx-suit]: https://github.com/nepalez/hexx-suit
80
+
81
+ Contributing
82
+ ------------
83
+
84
+ * Read the [STYLEGUIDE](config/metrics/STYLEGUIDE)
85
+ * [Fork the project](https://github.com/nepalez/query_builder)
86
+ * Create your feature branch (`git checkout -b my-new-feature`)
87
+ * Add tests for it
88
+ * Commit your changes (`git commit -am '[UPDATE] Add some feature'`)
89
+ * Push to the branch (`git push origin my-new-feature`)
90
+ * Create a new Pull Request
91
+
92
+ License
93
+ -------
94
+
95
+ See the [MIT LICENSE](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require "bundler/setup"
4
+ require "rubygems"
5
+
6
+ # Loads bundler tasks
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ # Loads the Hexx::RSpec and its tasks
10
+ begin
11
+ require "hexx-suit"
12
+ Hexx::Suit.install_tasks
13
+ rescue LoadError
14
+ require "hexx-rspec"
15
+ Hexx::RSpec.install_tasks
16
+ end
17
+
18
+ # Sets the Hexx::RSpec :test task to default
19
+ task :default do
20
+ system "bundle exec rake test:coverage:run"
21
+ end
22
+
23
+ desc "Runs mutation metric for testing"
24
+ task :mutant do
25
+ system "mutant -r ./spec/spec_helper --use rspec QueryBuilder* --fail-fast"
26
+ end
27
+
28
+ desc "Exhort all evils"
29
+ task :exhort do
30
+ system "mutant -r ./spec/spec_helper --use rspec QueryBuilder*"
31
+ end
32
+
33
+ desc "Runs all the necessary metrics before making a commit"
34
+ task prepare: %w(exhort check:inch check:rubocop check:fu)
@@ -0,0 +1,230 @@
1
+ = Ruby Style Guide
2
+
3
+ Adapted from Dan Kubb's Ruby Style Guide
4
+ https://github.com/dkubb/styleguide/blob/master/RUBY-STYLE
5
+
6
+ == Commiting:
7
+
8
+ * Write descriptive commit messages, following the pattern:
9
+
10
+ [TYPE] name
11
+
12
+ The message, describing the changes being made
13
+
14
+ * Use the types below to mark commits:
15
+
16
+ - FEATURE - for adding new features, or backward-compatible changes;
17
+ - CHANGE - for backward-incompatible changes;
18
+ - BUG FIX - for fixing bugs;
19
+ - REFACTORING - for other changes of the code not affecting the API;
20
+ - OTHER - for changes in documentaton, metrics etc, not touching the code;
21
+ - VERSION - for version changes.
22
+
23
+ * Always separate commits of different types (such as FEATURE and CHANGE).
24
+
25
+ * Try to separate various features from each other.
26
+
27
+ * Include specification to the same commit as the code.
28
+
29
+ * Run all tests before making a commit.
30
+ Never commit the code that break unit tests.
31
+
32
+ * Use metric (run `rake check`) before making a commit.
33
+
34
+ * Do refactoring before making a commit. Best writing is rewriting.
35
+
36
+ * Follow semantic versioning.
37
+
38
+ http://semver.org/
39
+
40
+ * For versions name the commit after a version number, following the pattern:
41
+
42
+ VERSION 1.0.0-rc2
43
+
44
+
45
+ == Formatting:
46
+
47
+ * Use UTF-8. Declare encoding in the first line of every file.
48
+
49
+ # encoding: utf-8
50
+
51
+ * Use 2 space indent, no tabs.
52
+
53
+ * Use Unix-style line endings.
54
+
55
+ * Use spaces around operators, after commas, colons and semicolons,
56
+ around { and before }.
57
+
58
+ * No spaces after (, [ and before ], ).
59
+
60
+ * Align `when` and `else` with `case`.
61
+
62
+ * Use an empty line before the return value of a method (unless it
63
+ only has one line), and an empty line between defs.
64
+
65
+ * Use empty lines to break up a long method into logical paragraphs.
66
+
67
+ * Keep lines fewer than 80 characters.
68
+
69
+ * Strip trailing whitespace.
70
+
71
+
72
+ == Syntax:
73
+
74
+ * Write for 2.0.
75
+
76
+ * Use double quotes
77
+
78
+ http://viget.com/extend/just-use-double-quoted-ruby-strings
79
+
80
+ * Use def with parentheses when there are arguments.
81
+
82
+ * Never use for, unless you exactly know why.
83
+
84
+ * Never use then, except in case statements.
85
+
86
+ * Use when x then ... for one-line cases.
87
+
88
+ * Use &&/|| for boolean expressions, and/or for control flow. (Rule
89
+ of thumb: If you have to use outer parentheses, you are using the
90
+ wrong operators.)
91
+
92
+ * Avoid double negation (!!), unless Null Objects are expected.
93
+
94
+ http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness
95
+
96
+ * Avoid multiline ?:, use if.
97
+
98
+ * Use {...} when defining blocks on one line. Use do...end for multiline
99
+ blocks.
100
+
101
+ * Avoid return where not required.
102
+
103
+ * Use ||= freely.
104
+
105
+ * Use OO regexps, and avoid =~ $0-9, $~, $` and $' when possible.
106
+
107
+ * Do not use Enumerable#inject when the "memo" object does not change between
108
+ iterations, use Enumerable#each_with_object instead (in ruby 1.9,
109
+ active_support and backports).
110
+
111
+ * Prefer ENV.fetch to ENV[] syntax.
112
+ Prefer block syntax for ENV.fetch to usage of the second argument.
113
+
114
+
115
+ == Naming:
116
+
117
+ * Use snake_case for methods.
118
+
119
+ * Use CamelCase for classes and modules. (Keep acronyms like HTTP,
120
+ RFC, XML uppercase.)
121
+
122
+ * Use SCREAMING_SNAKE_CASE for other constants.
123
+
124
+ * Do not use single letter variable names. Avoid uncommunicative names.
125
+
126
+ * Use consistent variable names. Try to keep the variable names close
127
+ to the object class name.
128
+
129
+ * Use names prefixed with _ for unused variables.
130
+
131
+ * When defining a predicate method that compares against another object of
132
+ a similar type, name the argument "other".
133
+
134
+ * Prefer map over collect, detect over find, select over find_all.
135
+
136
+ * Use def self.method to define singleton methods.
137
+
138
+ * Avoid alias when alias_method will do.
139
+
140
+
141
+ == Comments:
142
+
143
+ * Use YARD and its conventions for API documentation. Don't put an
144
+ empty line between the comment block and the def.
145
+
146
+ * Comments longer than a word are capitalized and use punctuation.
147
+ Use one space after periods.
148
+
149
+ * Avoid superfluous comments.
150
+
151
+
152
+ == Code structuring:
153
+
154
+ * Break code into packages, decoupled from the environment.
155
+
156
+ * Wrap packages into gems.
157
+
158
+ * Inject dependencies explicitly.
159
+ Leave all outer references on the border of any package. Inside
160
+ the package use internal references only.
161
+
162
+ * Follow SOLID principles.
163
+
164
+ http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
165
+
166
+ * Only give a method one purpose for existing. If you pass in a boolean
167
+ to a method, what you're saying is that this method has two different
168
+ behaviours. Just split it into two single purpose methods. If you have
169
+ to use the words "AND" or "OR" to describe what the method does it
170
+ probably does too much.
171
+
172
+ * Avoid long methods.
173
+ Try to keep them at no more than 6 lines long, and preferably 4 or less.
174
+
175
+ If sections of a method are logically separate by blank lines, then
176
+ that's probably a sign that those sections should be split into separate
177
+ methods.
178
+
179
+ * Avoid hashes-as-optional-parameters. Does the method do too much?
180
+
181
+ * Avoid long parameter lists.
182
+
183
+ * Add "global" methods to Kernel (if you have to) and make them private.
184
+
185
+ * Use OptionParser for parsing complex command line options and
186
+ ruby -s for trivial command line options.
187
+
188
+ * Avoid needless metaprogramming.
189
+
190
+ * Always freeze objects assigned to constants.
191
+
192
+
193
+ == General:
194
+
195
+ * Code in a functional way, avoid mutation when it makes sense.
196
+
197
+ * Try to have methods either return the state of the object and have
198
+ no side effects, or return self and have side effects. This is
199
+ otherwise known as Command-query separation (CQS):
200
+
201
+ http://en.wikipedia.org/wiki/Command-query_separation
202
+
203
+ * Do not mutate arguments unless that is the purpose of the method.
204
+
205
+ * Try following TRUE heuristics by Sandi Metz
206
+
207
+ http://designisrefactoring.com/2015/02/08/introducing-sandi-metz-true/
208
+
209
+ * Do not mess around in core classes when writing libraries.
210
+ Namespace your code inside the modules, or wrap core classes to
211
+ decorators of your own.
212
+
213
+ * Do not program defensively.
214
+
215
+ http://www.erlang.se/doc/programming_rules.shtml#HDR11
216
+
217
+ * Keep the code simple.
218
+
219
+ * Don't overdesign.
220
+
221
+ * Don't underdesign.
222
+
223
+ * Avoid bugs.
224
+
225
+ * Read other style guides and apply the parts that don't dissent with
226
+ this list.
227
+
228
+ * Be consistent.
229
+
230
+ * Use common sense.