rdbi-result-driver-json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Erik Hollensbe
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = rdbi-result-driver-json
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Erik Hollensbe. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rdbi-result-driver-json"
8
+ gem.summary = %Q{JSON result output for RDBI}
9
+ gem.description = gem.summary
10
+ gem.email = "erik@hollensbe.org"
11
+ gem.homepage = "http://github.com/RDBI/rdbi-result-driver-json"
12
+ gem.authors = ["Erik Hollensbe"]
13
+ gem.add_development_dependency "rdbi-driver-mock"
14
+ gem.add_dependency 'rdbi'
15
+ gem.add_dependency 'json'
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+ # FIXME doc tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+
3
+ class RDBI::Result::Driver::JSON < RDBI::Result::Driver
4
+ def initialize(result, *args)
5
+ super
6
+
7
+ @as_object = false
8
+
9
+ if args[0].kind_of?(Hash)
10
+ @as_object = args[0][:as_hash] || args[0][:as_object]
11
+ end
12
+ end
13
+
14
+ def fetch(row_count)
15
+ if @as_object
16
+ obj_hash = { }
17
+ index = []
18
+ results = []
19
+
20
+ @result.schema.columns.map(&:name).each { |name| index.push(name); obj_hash[name] = nil }
21
+
22
+ @result.raw_fetch(row_count).each do |row|
23
+ my_hash = obj_hash.dup
24
+ row.each_with_index do |col, i|
25
+ my_hash[index[i]] = col
26
+ end
27
+ results.push my_hash
28
+ end
29
+
30
+ return ::JSON.dump(results)
31
+ else
32
+ return ::JSON.dump(@result.raw_fetch(row_count))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rdbi-result-driver-json}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Erik Hollensbe"]
12
+ s.date = %q{2010-08-21}
13
+ s.description = %q{JSON result output for RDBI}
14
+ s.email = %q{erik@hollensbe.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rdbi/result/driver/json.rb",
27
+ "rdbi-result-driver-json.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_driver.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/RDBI/rdbi-result-driver-json}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{JSON result output for RDBI}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_driver.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rdbi-driver-mock>, [">= 0"])
47
+ s.add_runtime_dependency(%q<rdbi>, [">= 0"])
48
+ s.add_runtime_dependency(%q<json>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rdbi-driver-mock>, [">= 0"])
51
+ s.add_dependency(%q<rdbi>, [">= 0"])
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rdbi-driver-mock>, [">= 0"])
56
+ s.add_dependency(%q<rdbi>, [">= 0"])
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ end
59
+ end
60
+
data/test/helper.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ gem 'test-unit'
3
+ gem 'rdbi'
4
+ gem 'rdbi-driver-mock'
5
+ require 'test/unit'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ require 'rdbi'
10
+ require 'rdbi/driver/mock'
11
+ require 'rdbi/result/driver/json'
12
+
13
+ class Test::Unit::TestCase
14
+ def mock_connect
15
+ RDBI.connect(:Mock)
16
+ end
17
+
18
+ def mock_statement_with_results(dbh, results)
19
+ sth = dbh.prepare("some statmeent")
20
+ sth.result = results
21
+ return sth
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestDriver < Test::Unit::TestCase
4
+ def setup
5
+ @dbh = mock_connect
6
+ end
7
+
8
+ def teardown
9
+ @dbh.disconnect
10
+ end
11
+
12
+ def test_01_results_working
13
+ sth = mock_statement_with_results(@dbh, [[1,2,3]])
14
+
15
+ json = sth.execute.fetch(:all, :JSON)
16
+ assert_equal('[[1,2,3]]', json)
17
+
18
+ json = sth.execute.as(:JSON).fetch(:all)
19
+ assert_equal('[[1,2,3]]', json)
20
+
21
+ sth.finish
22
+ end
23
+
24
+ def test_02_as_object_results
25
+ # XXX extra fields here are due to the default fields the mock yields.
26
+ sth = mock_statement_with_results(@dbh, [[1,2,3]])
27
+
28
+ json = sth.execute.fetch(:all, :JSON, :as_object => true)
29
+ assert_equal("[{\"5\":null,\"0\":1,\"6\":null,\"1\":2,\"7\":null,\"2\":3,\"8\":null,\"3\":null,\"9\":null,\"4\":null}]", json)
30
+
31
+ json = sth.execute.as(:JSON, :as_object => true).fetch(:all)
32
+ assert_equal("[{\"5\":null,\"0\":1,\"6\":null,\"1\":2,\"7\":null,\"2\":3,\"8\":null,\"3\":null,\"9\":null,\"4\":null}]", json)
33
+
34
+ sth.finish
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdbi-result-driver-json
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Erik Hollensbe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-21 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rdbi-driver-mock
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rdbi
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: JSON result output for RDBI
64
+ email: erik@hollensbe.org
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - LICENSE
71
+ - README.rdoc
72
+ files:
73
+ - .document
74
+ - .gitignore
75
+ - LICENSE
76
+ - README.rdoc
77
+ - Rakefile
78
+ - VERSION
79
+ - lib/rdbi/result/driver/json.rb
80
+ - rdbi-result-driver-json.gemspec
81
+ - test/helper.rb
82
+ - test/test_driver.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/RDBI/rdbi-result-driver-json
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: JSON result output for RDBI
117
+ test_files:
118
+ - test/helper.rb
119
+ - test/test_driver.rb