veritas-do-adapter 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.document +5 -0
  2. data/.gemtest +0 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +46 -0
  6. data/Guardfile +18 -0
  7. data/LICENSE +20 -0
  8. data/README.md +21 -0
  9. data/Rakefile +27 -0
  10. data/TODO +0 -0
  11. data/config/flay.yml +3 -0
  12. data/config/flog.yml +2 -0
  13. data/config/roodi.yml +16 -0
  14. data/config/site.reek +96 -0
  15. data/config/yardstick.yml +2 -0
  16. data/lib/veritas/adapter/data_objects/statement.rb +107 -0
  17. data/lib/veritas/adapter/data_objects/version.rb +9 -0
  18. data/lib/veritas/adapter/data_objects.rb +55 -0
  19. data/lib/veritas/relation/gateway.rb +363 -0
  20. data/lib/veritas-do-adapter.rb +4 -0
  21. data/spec/rcov.opts +6 -0
  22. data/spec/shared/binary_relation_method_behaviour.rb +51 -0
  23. data/spec/shared/command_method_behavior.rb +7 -0
  24. data/spec/shared/each_method_behaviour.rb +15 -0
  25. data/spec/shared/idempotent_method_behaviour.rb +7 -0
  26. data/spec/shared/unary_relation_method_behaviour.rb +21 -0
  27. data/spec/spec.opts +3 -0
  28. data/spec/spec_helper.rb +28 -0
  29. data/spec/unit/veritas/adapter/data_objects/class_methods/new_spec.rb +15 -0
  30. data/spec/unit/veritas/adapter/data_objects/read_spec.rb +70 -0
  31. data/spec/unit/veritas/adapter/data_objects/statement/class_methods/new_spec.rb +28 -0
  32. data/spec/unit/veritas/adapter/data_objects/statement/each_spec.rb +63 -0
  33. data/spec/unit/veritas/adapter/data_objects/statement/to_s_spec.rb +53 -0
  34. data/spec/unit/veritas/relation/gateway/class_methods/new_spec.rb +16 -0
  35. data/spec/unit/veritas/relation/gateway/difference_spec.rb +17 -0
  36. data/spec/unit/veritas/relation/gateway/drop_spec.rb +21 -0
  37. data/spec/unit/veritas/relation/gateway/each_spec.rb +84 -0
  38. data/spec/unit/veritas/relation/gateway/extend_spec.rb +27 -0
  39. data/spec/unit/veritas/relation/gateway/intersect_spec.rb +17 -0
  40. data/spec/unit/veritas/relation/gateway/join_spec.rb +44 -0
  41. data/spec/unit/veritas/relation/gateway/materialize_spec.rb +27 -0
  42. data/spec/unit/veritas/relation/gateway/optimize_spec.rb +23 -0
  43. data/spec/unit/veritas/relation/gateway/product_spec.rb +17 -0
  44. data/spec/unit/veritas/relation/gateway/project_spec.rb +21 -0
  45. data/spec/unit/veritas/relation/gateway/remove_spec.rb +21 -0
  46. data/spec/unit/veritas/relation/gateway/rename_spec.rb +21 -0
  47. data/spec/unit/veritas/relation/gateway/respond_to_spec.rb +29 -0
  48. data/spec/unit/veritas/relation/gateway/restrict_spec.rb +27 -0
  49. data/spec/unit/veritas/relation/gateway/reverse_spec.rb +21 -0
  50. data/spec/unit/veritas/relation/gateway/sort_by_spec.rb +27 -0
  51. data/spec/unit/veritas/relation/gateway/summarize_spec.rb +148 -0
  52. data/spec/unit/veritas/relation/gateway/take_spec.rb +21 -0
  53. data/spec/unit/veritas/relation/gateway/union_spec.rb +17 -0
  54. data/tasks/metrics/ci.rake +7 -0
  55. data/tasks/metrics/flay.rake +41 -0
  56. data/tasks/metrics/flog.rake +43 -0
  57. data/tasks/metrics/heckle.rake +209 -0
  58. data/tasks/metrics/metric_fu.rake +29 -0
  59. data/tasks/metrics/reek.rake +9 -0
  60. data/tasks/metrics/roodi.rake +15 -0
  61. data/tasks/metrics/yardstick.rake +23 -0
  62. data/tasks/spec.rake +39 -0
  63. data/tasks/yard.rake +9 -0
  64. data/veritas-do-adapter.gemspec +124 -0
  65. metadata +257 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gemtest ADDED
File without changes
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use @$(basename `pwd`) --create
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ bundler_args: --without guard metrics
2
+ script: "bundle exec rake spec"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ruby-head
8
+ - ree
9
+ - jruby
10
+ - rbx
11
+ - rbx-2.0
data/Gemfile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ source :rubygems
4
+
5
+ gem 'data_objects', '~> 0.10.6', :git => 'git://github.com/datamapper/do.git'
6
+ gem 'veritas', '~> 0.0.6', :git => 'git://github.com/dkubb/veritas.git'
7
+ gem 'veritas-sql-generator', '~> 0.0.6', :git => 'git://github.com/dkubb/veritas-sql-generator.git'
8
+
9
+ group :development do
10
+ gem 'backports', '~> 2.3.0'
11
+ gem 'jeweler', '~> 1.6.4'
12
+ gem 'rake', '~> 0.9.2'
13
+ gem 'rspec', '~> 1.3.2'
14
+ gem 'yard', '~> 0.7.2'
15
+ end
16
+
17
+ group :guard do
18
+ gem 'guard', '~> 0.7.0'
19
+ gem 'guard-bundler', '~> 0.1.3'
20
+ gem 'guard-rspec', '~> 0.4.5'
21
+ end
22
+
23
+ platform :jruby do
24
+ group :jruby do
25
+ gem 'jruby-openssl', '~> 0.7.4'
26
+ end
27
+ end
28
+
29
+ platforms :mri_18 do
30
+ group :metrics do
31
+ gem 'arrayfields', '~> 4.7.4'
32
+ gem 'fattr', '~> 2.2.0'
33
+ gem 'flay', '~> 1.4.2'
34
+ gem 'flog', '~> 2.5.3'
35
+ gem 'heckle', '~> 1.4.3'
36
+ gem 'json', '~> 1.6.1'
37
+ gem 'map', '~> 4.4.0'
38
+ gem 'metric_fu', '~> 2.1.1'
39
+ gem 'mspec', '~> 1.5.17'
40
+ gem 'rcov', '~> 0.9.9'
41
+ gem 'reek', '~> 1.2.8', :git => 'git://github.com/dkubb/reek.git'
42
+ gem 'roodi', '~> 2.1.0'
43
+ gem 'ruby2ruby', '= 1.2.2'
44
+ gem 'yardstick', '~> 0.4.0'
45
+ end
46
+ end
data/Guardfile ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ guard 'bundler' do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard 'rspec' do
8
+ # run all specs if the spec_helper or supporting files files are modified
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
11
+
12
+ # run unit specs if associated lib code is modified
13
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
14
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
15
+
16
+ # run a spec if it is modified
17
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Kubb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Veritas DataObjects Adapter
2
+
3
+ Use Veritas relations with an RDBMS
4
+
5
+ [![Build Status](https://secure.travis-ci.org/dkubb/veritas-do-adapter.png)](http://travis-ci.org/dkubb/veritas-do-adapter)
6
+
7
+ ## Note on Patches/Pull Requests
8
+
9
+ * If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and it may not always be clear the direction it is going. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
10
+ * Fork the project.
11
+ * Make your feature addition or bug fix.
12
+ * Follow this [style guide](https://github.com/dkubb/styleguide).
13
+ * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
14
+ * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
15
+ * Run "rake ci". This must pass and not show any regressions in the
16
+ metrics for the code to be merged.
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ ## Copyright
20
+
21
+ Copyright © 2011 Dan Kubb. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+
5
+ require File.expand_path('../lib/veritas/adapter/data_objects/version', __FILE__)
6
+
7
+ begin
8
+ gem('jeweler', '~> 1.6.2') if respond_to?(:gem, true)
9
+ require 'jeweler'
10
+
11
+ Jeweler::Tasks.new do |gem|
12
+ gem.name = 'veritas-do-adapter'
13
+ gem.summary = 'Vertias DataObjects adapter'
14
+ gem.description = 'Use Veritas relations with an RDBMS'
15
+ gem.email = 'dan.kubb@gmail.com'
16
+ gem.homepage = 'https://github.com/dkubb/veritas-do-adapter'
17
+ gem.authors = [ 'Dan Kubb' ]
18
+
19
+ gem.version = Veritas::Adapter::DataObjects::VERSION
20
+ end
21
+
22
+ Jeweler::GemcutterTasks.new
23
+
24
+ FileList['tasks/**/*.rake'].each { |task| import task }
25
+ rescue LoadError
26
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.2'
27
+ end
data/TODO ADDED
File without changes
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 11
3
+ total_score: 57.0
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 12.9
data/config/roodi.yml ADDED
@@ -0,0 +1,16 @@
1
+ ---
2
+ AbcMetricMethodCheck: { score: 11.8 }
3
+ AssignmentInConditionalCheck: { }
4
+ CaseMissingElseCheck: { }
5
+ ClassLineCountCheck: { line_count: 357 }
6
+ ClassNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
7
+ ClassVariableCheck: { }
8
+ CyclomaticComplexityBlockCheck: { complexity: 2 }
9
+ CyclomaticComplexityMethodCheck: { complexity: 5 }
10
+ EmptyRescueBodyCheck: { }
11
+ ForLoopCheck: { }
12
+ MethodLineCountCheck: { line_count: 9 }
13
+ MethodNameCheck: { pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/ }
14
+ ModuleLineCountCheck: { line_count: 359 }
15
+ ModuleNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
16
+ ParameterNumberCheck: { parameter_count: 3 }
data/config/site.reek ADDED
@@ -0,0 +1,96 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ LargeClass:
11
+ max_methods: 18
12
+ exclude: []
13
+ enabled: true
14
+ max_instance_variables: 5
15
+ UncommunicativeMethodName:
16
+ accept: []
17
+ exclude: []
18
+ enabled: true
19
+ reject:
20
+ - !ruby/regexp /^[a-z]$/
21
+ - !ruby/regexp /[0-9]$/
22
+ - !ruby/regexp /[A-Z]/
23
+ LongParameterList:
24
+ max_params: 3
25
+ exclude: []
26
+ enabled: true
27
+ overrides: {}
28
+ FeatureEnvy:
29
+ exclude: [
30
+ 'Veritas::Adapter::DataObjects::Statement#each_row',
31
+ 'Veritas::Relation::Gateway#same_adapter?',
32
+ 'Veritas::Relation::Gateway#summarize_merge?',
33
+ 'Veritas::Relation::Gateway#summarize_merge'
34
+ ]
35
+ enabled: true
36
+ ClassVariable:
37
+ exclude: []
38
+ enabled: true
39
+ BooleanParameter:
40
+ exclude: []
41
+ enabled: true
42
+ IrresponsibleModule:
43
+ exclude: [ 'Veritas::Relation' ]
44
+ enabled: true
45
+ UncommunicativeModuleName:
46
+ accept: []
47
+ exclude: []
48
+ enabled: true
49
+ reject:
50
+ - !ruby/regexp /^.$/
51
+ - !ruby/regexp /[0-9]$/
52
+ NestedIterators:
53
+ ignore_iterators: []
54
+ exclude: []
55
+ enabled: true
56
+ max_allowed_nesting: 1
57
+ LongMethod:
58
+ max_statements: 7
59
+ exclude: []
60
+ enabled: true
61
+ Duplication:
62
+ allow_calls: []
63
+ exclude: []
64
+ enabled: true
65
+ max_calls: 1
66
+ UtilityFunction:
67
+ max_helper_calls: 1
68
+ exclude: []
69
+ enabled: true
70
+ Attribute:
71
+ exclude: []
72
+ enabled: false
73
+ UncommunicativeVariableName:
74
+ accept: []
75
+ exclude: []
76
+ enabled: true
77
+ reject:
78
+ - !ruby/regexp /^.$/
79
+ - !ruby/regexp /[0-9]$/
80
+ - !ruby/regexp /[A-Z]/
81
+ SimulatedPolymorphism:
82
+ exclude: []
83
+ enabled: true
84
+ max_ifs: 1
85
+ DataClump:
86
+ exclude: []
87
+ enabled: true
88
+ max_copies: 1
89
+ min_clump_size: 2
90
+ ControlCouple:
91
+ exclude: []
92
+ enabled: true
93
+ LongYieldList:
94
+ max_params: 2
95
+ exclude: []
96
+ enabled: true
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ module Adapter
5
+ class DataObjects
6
+
7
+ # Executes generated SQL statements
8
+ class Statement
9
+ include Enumerable, Immutable
10
+
11
+ # Initialize a statement
12
+ #
13
+ # @param [::DataObjects::Connection] connection
14
+ # the database connection
15
+ # @param [Relation] relation
16
+ # the relation to generate the SQL from
17
+ # @param [#visit] visitor
18
+ # optional object to visit the relation and generate SQL with
19
+ #
20
+ # @return [undefined]
21
+ #
22
+ # @api private
23
+ def initialize(connection, relation, visitor = SQL::Generator::Relation)
24
+ @connection = connection
25
+ @relation = relation
26
+ @visitor = visitor
27
+ end
28
+
29
+ # Iterate over each row in the results
30
+ #
31
+ # @example
32
+ # statement = Statement.new(connection, relation, visitor)
33
+ # statement.each { |row| ... }
34
+ #
35
+ # @yield [row]
36
+ #
37
+ # @yieldparam [Array] row
38
+ # each row in the results
39
+ #
40
+ # @return [self]
41
+ #
42
+ # @api public
43
+ def each
44
+ return to_enum unless block_given?
45
+ each_row { |row| yield row }
46
+ self
47
+ end
48
+
49
+ # Return the SQL query
50
+ #
51
+ # @example
52
+ # statement.to_s # => SQL representation of the relation
53
+ #
54
+ # @return [String]
55
+ #
56
+ # @api public
57
+ def to_s
58
+ @visitor.visit(@relation).to_sql.freeze
59
+ end
60
+
61
+ private
62
+
63
+ # Yield each row in the result
64
+ #
65
+ # @yield [row]
66
+ #
67
+ # @yieldparam [Array] row
68
+ # each row in the results
69
+ #
70
+ # @return [undefined]
71
+ #
72
+ # @api private
73
+ def each_row
74
+ reader = command.execute_reader
75
+ while reader.next!
76
+ yield reader.values
77
+ end
78
+ ensure
79
+ reader.close if reader
80
+ end
81
+
82
+ # Return the command for the SQL query and column types
83
+ #
84
+ # @return [::DataObjects::Command]
85
+ #
86
+ # @api private
87
+ def command
88
+ command = @connection.create_command(to_s)
89
+ command.set_types(column_types)
90
+ command
91
+ end
92
+
93
+ # Return the list of types for each column
94
+ #
95
+ # @return [Array<Class>]
96
+ #
97
+ # @api private
98
+ def column_types
99
+ @relation.header.map { |attribute| attribute.class.primitive }
100
+ end
101
+
102
+ memoize :to_s, :command
103
+
104
+ end # class Statement
105
+ end # class DataObjects
106
+ end # module Adapter
107
+ end # module Veritas
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ module Adapter
5
+ class DataObjects
6
+ VERSION = '0.0.5'
7
+ end # class DataObjects
8
+ end # module Adapter
9
+ end # module Veritas
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'veritas'
4
+ require 'veritas-sql-generator'
5
+ require 'data_objects'
6
+
7
+ module Veritas
8
+ module Adapter
9
+
10
+ # An adapter wrapping a DataObjects connection
11
+ class DataObjects
12
+ include Immutable
13
+
14
+ # Initialize a DataObjects adapter
15
+ #
16
+ # @param [String] uri
17
+ #
18
+ # @return [undefined]
19
+ #
20
+ # @api private
21
+ def initialize(uri)
22
+ @uri = uri
23
+ end
24
+
25
+ # Read the results from the SQL representation of the relation
26
+ #
27
+ # @example
28
+ # adapter.read(relation) { |row| ... }
29
+ #
30
+ # @param [Relation] relation
31
+ #
32
+ # @yield [row]
33
+ #
34
+ # @yieldparam [Array] row
35
+ # each row in the results
36
+ #
37
+ # @return [self]
38
+ #
39
+ # @api public
40
+ def read(relation)
41
+ return to_enum(__method__, relation) unless block_given?
42
+ connection = ::DataObjects::Connection.new(@uri)
43
+ Statement.new(connection, relation).each { |row| yield row }
44
+ self
45
+ ensure
46
+ connection.close if connection
47
+ end
48
+
49
+ end # class DataObjects
50
+ end # module Adapter
51
+ end # module Veritas
52
+
53
+ require 'veritas/adapter/data_objects/version'
54
+
55
+ require 'veritas/adapter/data_objects/statement'