rom-cassandra 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +26 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +7 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +83 -0
- data/Rakefile +34 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +14 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +84 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +6 -0
- data/config/metrics/yardstick.yml +37 -0
- data/lib/rom-cassandra.rb +3 -0
- data/lib/rom/cassandra.rb +33 -0
- data/lib/rom/cassandra/commands.rb +53 -0
- data/lib/rom/cassandra/commands/batch.rb +54 -0
- data/lib/rom/cassandra/commands/create.rb +38 -0
- data/lib/rom/cassandra/commands/delete.rb +38 -0
- data/lib/rom/cassandra/commands/update.rb +38 -0
- data/lib/rom/cassandra/dataset.rb +102 -0
- data/lib/rom/cassandra/gateway.rb +115 -0
- data/lib/rom/cassandra/migrations.rb +30 -0
- data/lib/rom/cassandra/migrations/generator.rb +68 -0
- data/lib/rom/cassandra/migrations/generator/migration.erb +32 -0
- data/lib/rom/cassandra/migrations/logger.rb +28 -0
- data/lib/rom/cassandra/migrations/migration.rb +107 -0
- data/lib/rom/cassandra/migrations/migrator.rb +103 -0
- data/lib/rom/cassandra/migrations/runner.rb +119 -0
- data/lib/rom/cassandra/migrations/runner_down.rb +49 -0
- data/lib/rom/cassandra/migrations/runner_up.rb +50 -0
- data/lib/rom/cassandra/query.rb +43 -0
- data/lib/rom/cassandra/relation.rb +88 -0
- data/lib/rom/cassandra/session.rb +50 -0
- data/lib/rom/cassandra/tasks.rb +6 -0
- data/lib/rom/cassandra/version.rb +15 -0
- data/lib/tasks/db.rake +16 -0
- data/rom-cassandra.gemspec +33 -0
- data/spec/config/reset_cluster.rb +28 -0
- data/spec/config/rom.rb +3 -0
- data/spec/config/test_module.rb +7 -0
- data/spec/integration/batch_spec.rb +36 -0
- data/spec/integration/create_spec.rb +33 -0
- data/spec/integration/delete_spec.rb +33 -0
- data/spec/integration/migrate/20150825142003_create_users.rb +24 -0
- data/spec/integration/migrate/20150825142024_create_logs.rb +17 -0
- data/spec/integration/migrate_spec.rb +47 -0
- data/spec/integration/relation_spec.rb +27 -0
- data/spec/integration/update_spec.rb +33 -0
- data/spec/shared/fake_migrate_folder.rb +21 -0
- data/spec/shared/users.rb +20 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/commands/batch_spec.rb +86 -0
- data/spec/unit/commands/create_spec.rb +77 -0
- data/spec/unit/commands/delete_spec.rb +77 -0
- data/spec/unit/commands/update_spec.rb +77 -0
- data/spec/unit/dataset_spec.rb +130 -0
- data/spec/unit/gateway_spec.rb +140 -0
- data/spec/unit/migrations/generator_spec.rb +31 -0
- data/spec/unit/migrations/logger_spec.rb +21 -0
- data/spec/unit/migrations/migration_spec.rb +59 -0
- data/spec/unit/migrations/migrator_spec.rb +120 -0
- data/spec/unit/migrations/runner_down_spec.rb +65 -0
- data/spec/unit/migrations/runner_spec.rb +142 -0
- data/spec/unit/migrations/runner_up_spec.rb +67 -0
- data/spec/unit/query_spec.rb +21 -0
- data/spec/unit/relation_spec.rb +142 -0
- data/spec/unit/session_spec.rb +55 -0
- data/spec/unit/tasks/create_migration_spec.rb +41 -0
- metadata +242 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
folders: # The list of folders to be used by any metric.
|
3
|
+
- lib
|
4
|
+
metrics: # The list of allowed metrics. The other metrics are disabled.
|
5
|
+
- cane
|
6
|
+
- churn
|
7
|
+
- flay
|
8
|
+
- flog
|
9
|
+
- reek
|
10
|
+
- roodi
|
11
|
+
- saikuro
|
12
|
+
format: html
|
13
|
+
output: tmp/metric_fu
|
14
|
+
verbose: false
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
AssignmentInConditionalCheck:
|
3
|
+
CaseMissingElseCheck:
|
4
|
+
ClassLineCountCheck:
|
5
|
+
line_count: 200
|
6
|
+
ClassNameCheck:
|
7
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
8
|
+
ClassVariableCheck:
|
9
|
+
CyclomaticComplexityBlockCheck:
|
10
|
+
complexity: 3
|
11
|
+
CyclomaticComplexityMethodCheck:
|
12
|
+
complexity: 4
|
13
|
+
EmptyRescueBodyCheck:
|
14
|
+
ForLoopCheck:
|
15
|
+
MethodLineCountCheck:
|
16
|
+
line_count: 6
|
17
|
+
MethodNameCheck:
|
18
|
+
pattern: !ruby/regexp /^[\||\^|\&|\!]$|^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 200
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 4
|
@@ -0,0 +1,84 @@
|
|
1
|
+
---
|
2
|
+
# settings added by the 'hexx-suit' module
|
3
|
+
# output: "tmp/rubocop"
|
4
|
+
# format: "html"
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- '**/db/schema.rb'
|
9
|
+
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- '**/*_spec.rb'
|
13
|
+
|
14
|
+
Lint/RescueException:
|
15
|
+
Exclude:
|
16
|
+
- '**/*_spec.rb'
|
17
|
+
|
18
|
+
Metrics/LineLength:
|
19
|
+
Exclude:
|
20
|
+
- '**/spec/config/*.rb' # allow long CQL statements
|
21
|
+
- '**/*_spec.rb'
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Exclude:
|
25
|
+
- '**/integration/migrate/*.rb' # allow long migrations
|
26
|
+
|
27
|
+
Style/AccessorMethodName:
|
28
|
+
Exclude:
|
29
|
+
- '**/*_spec.rb'
|
30
|
+
|
31
|
+
Style/AsciiComments:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/ClassAndModuleChildren:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/EmptyLinesAroundBlockBody:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/EmptyLinesAroundClassBody:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/EmptyLinesAroundMethodBody:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/EmptyLinesAroundModuleBody:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/EmptyLineBetweenDefs:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/FileName:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/NumericLiterals:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Style/RaiseArgs:
|
62
|
+
EnforcedStyle: compact
|
63
|
+
|
64
|
+
Style/SingleLineMethods:
|
65
|
+
Exclude:
|
66
|
+
- '**/*_spec.rb'
|
67
|
+
|
68
|
+
Style/SingleSpaceBeforeFirstArg:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/SpecialGlobalVars:
|
72
|
+
Exclude:
|
73
|
+
- '**/Gemfile'
|
74
|
+
- '**/*.gemspec'
|
75
|
+
|
76
|
+
Style/StringLiterals:
|
77
|
+
EnforcedStyle: double_quotes
|
78
|
+
|
79
|
+
Style/StringLiteralsInInterpolation:
|
80
|
+
EnforcedStyle: double_quotes
|
81
|
+
|
82
|
+
Style/TrivialAccessors:
|
83
|
+
Exclude:
|
84
|
+
- '**/*_spec.rb'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
# Settings added by the 'hexx-suit' gem
|
3
|
+
output: "tmp/yardstick/output.log"
|
4
|
+
path: "lib/**/*.rb"
|
5
|
+
rules:
|
6
|
+
ApiTag::Presence:
|
7
|
+
enabled: true
|
8
|
+
exclude: []
|
9
|
+
ApiTag::Inclusion:
|
10
|
+
enabled: true
|
11
|
+
exclude: []
|
12
|
+
ApiTag::ProtectedMethod:
|
13
|
+
enabled: true
|
14
|
+
exclude: []
|
15
|
+
ApiTag::PrivateMethod:
|
16
|
+
enabled: false
|
17
|
+
exclude: []
|
18
|
+
ExampleTag:
|
19
|
+
enabled: true
|
20
|
+
exclude: []
|
21
|
+
ReturnTag:
|
22
|
+
enabled: true
|
23
|
+
exclude: []
|
24
|
+
Summary::Presence:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
Summary::Length:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
Summary::Delimiter:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
Summary::SingleLine:
|
34
|
+
enabled: true
|
35
|
+
exclude: []
|
36
|
+
threshold: 100
|
37
|
+
verbose: false
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rom"
|
4
|
+
|
5
|
+
# Ruby Object Mapper
|
6
|
+
#
|
7
|
+
# @see http://rom-rb.org ROM homepage
|
8
|
+
#
|
9
|
+
module ROM
|
10
|
+
|
11
|
+
# Apache Cassandra support for ROM
|
12
|
+
#
|
13
|
+
# @see http://cassandra.apache.org/ Apache Cassandra project
|
14
|
+
# @see http://datastax.github.io/ruby-driver/ Ruby driver for Cassandra
|
15
|
+
# @see http://github.com/nepalez/query_builder CQL query builder
|
16
|
+
#
|
17
|
+
module Cassandra
|
18
|
+
|
19
|
+
require_relative "cassandra/session"
|
20
|
+
require_relative "cassandra/query"
|
21
|
+
|
22
|
+
require_relative "cassandra/dataset"
|
23
|
+
require_relative "cassandra/gateway"
|
24
|
+
require_relative "cassandra/relation"
|
25
|
+
require_relative "cassandra/commands"
|
26
|
+
|
27
|
+
require_relative "cassandra/migrations"
|
28
|
+
|
29
|
+
end # module Cassandra
|
30
|
+
|
31
|
+
register_adapter(:cassandra, Cassandra)
|
32
|
+
|
33
|
+
end # module ROM
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ROM::Cassandra
|
4
|
+
|
5
|
+
# The collection of Cassandra-specific ROM commands
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
#
|
9
|
+
module Commands
|
10
|
+
|
11
|
+
# @private
|
12
|
+
def self.included(klass)
|
13
|
+
klass.__send__ :adapter, :cassandra
|
14
|
+
klass.__send__ :option, :initial, default: true
|
15
|
+
end
|
16
|
+
|
17
|
+
# Restricts the relation by a corresponding request
|
18
|
+
#
|
19
|
+
def initialize(*)
|
20
|
+
super
|
21
|
+
@relation = relation.public_send(restriction) if options.fetch(:initial)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Implements the execute method of the `ROM::Command` abstract class
|
25
|
+
#
|
26
|
+
# @yield the block to specify the statement.
|
27
|
+
#
|
28
|
+
# @return [Array]
|
29
|
+
# The empty array (Cassandra doesn't select rows when writes data).
|
30
|
+
#
|
31
|
+
def execute(*, &block)
|
32
|
+
(block_given? ? instance_eval(&block) : self).to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def method_missing(name, *args)
|
38
|
+
updated_relation = relation.public_send(name, *args)
|
39
|
+
self.class.new updated_relation, initial: nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def respond_to_missing?(name, *)
|
43
|
+
relation.respond_to? name
|
44
|
+
end
|
45
|
+
|
46
|
+
end # module Commands
|
47
|
+
|
48
|
+
require_relative "commands/create"
|
49
|
+
require_relative "commands/update"
|
50
|
+
require_relative "commands/delete"
|
51
|
+
require_relative "commands/batch"
|
52
|
+
|
53
|
+
end # module ROM::Cassandra
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ROM::Cassandra
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
# Implements the cassandra-specific Batch command
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# class Batch < ROM::Cassandra::Batch
|
11
|
+
# relation :items
|
12
|
+
# register_as :batch
|
13
|
+
#
|
14
|
+
# def execute
|
15
|
+
# super {
|
16
|
+
# self
|
17
|
+
# .add(keyspace(:domain).table(:items).delete.where(id: 1))
|
18
|
+
# .add("INSERT INTO logs.items (id, text) VALUES (1, 'deleted');")
|
19
|
+
# }
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# rom.command(:users).batch.call
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
#
|
27
|
+
class Batch < ROM::Command
|
28
|
+
|
29
|
+
include Commands
|
30
|
+
|
31
|
+
# Returns the keyspace context for lazy queries.
|
32
|
+
#
|
33
|
+
# The method can be used within a block of [#execute] to prepare
|
34
|
+
# commands for adding to the batch.
|
35
|
+
#
|
36
|
+
# @param [#to_s] name The name of the keyspace
|
37
|
+
#
|
38
|
+
# @return [ROM::Cassandra::Query]
|
39
|
+
#
|
40
|
+
def keyspace(name)
|
41
|
+
Query.new.keyspace(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def restriction
|
47
|
+
:batch_query
|
48
|
+
end
|
49
|
+
|
50
|
+
end # class Create
|
51
|
+
|
52
|
+
end # module Commands
|
53
|
+
|
54
|
+
end # module ROM::Cassandra
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ROM::Cassandra
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
# Implements the cassandra-specific Create command
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# class CreateName < ROM::Commands::Create[:cassandra]
|
11
|
+
# relation :items
|
12
|
+
# register_as :create
|
13
|
+
#
|
14
|
+
# def execute(id, name)
|
15
|
+
# super { insert(id: id, name: name).using(consistency: :quorum) }
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# create = rom.command(:users).create
|
20
|
+
# create.call(1, "Andrew")
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
#
|
24
|
+
class Create < ROM::Commands::Create
|
25
|
+
|
26
|
+
include Commands
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def restriction
|
31
|
+
:insert_query
|
32
|
+
end
|
33
|
+
|
34
|
+
end # class Create
|
35
|
+
|
36
|
+
end # module Commands
|
37
|
+
|
38
|
+
end # module ROM::Cassandra
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ROM::Cassandra
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
# Implements the cassandra-specific Delete command
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# class DeleteColumns < ROM::Commands::Delete[:cassandra]
|
11
|
+
# dataset(:users)
|
12
|
+
# register_as(:delete_columns)
|
13
|
+
#
|
14
|
+
# def execute(id, *cols)
|
15
|
+
# super { delete(*cols).where(id: id).using(consistency: :quorum) }
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# delete_columns = rom.command(:users).delete_columns
|
20
|
+
# delete_columns.call(1, :text)
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
#
|
24
|
+
class Delete < ROM::Commands::Delete
|
25
|
+
|
26
|
+
include Commands
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def restriction
|
31
|
+
:delete_query
|
32
|
+
end
|
33
|
+
|
34
|
+
end # class Delete
|
35
|
+
|
36
|
+
end # module Commands
|
37
|
+
|
38
|
+
end # module ROM::Cassandra
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ROM::Cassandra
|
4
|
+
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
# Implements the cassandra-specific Update command
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# class UpdateName < ROM::Commands::Update[:cassandra]
|
11
|
+
# relation :items
|
12
|
+
# register_as :update_name
|
13
|
+
#
|
14
|
+
# def execture(id, name)
|
15
|
+
# super { set(name: name).where(id: id).using(consistency: :quorum) }
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# update_name = rom.command(:users).update_name
|
20
|
+
# update_name.call(1, "Andrew")
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
#
|
24
|
+
class Update < ROM::Commands::Update
|
25
|
+
|
26
|
+
include Commands
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def restriction
|
31
|
+
:update_query
|
32
|
+
end
|
33
|
+
|
34
|
+
end # class Create
|
35
|
+
|
36
|
+
end # module Commands
|
37
|
+
|
38
|
+
end # module ROM::Cassandra
|