sequel_column_type_array 0.0.2

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,22 @@
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
+ nbproject
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2010 Corin Langosch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ =About
2
+
3
+ Sequel extension which allows easy use of array column types with databases that support them, ex. Postgresql.
4
+
5
+ ==Install
6
+
7
+ Simply install it as any other gem:
8
+
9
+ gem install sequel_column_type_array
10
+
11
+ Or when using bundler, add it got your Gemfile:
12
+
13
+ gem sequel_column_type_array
14
+
15
+ Thant's all, no need to do anything more.
16
+
17
+ ==Limits/ known bugs
18
+ * Only one dimensional arrays are supported
19
+ * Only column types "integer[]", "character (varying)[]" are currently supported
20
+ * Not all sequel conditionials are supported (ex you have to use filter{{:value => any(:array)}} instead of filter(:value => :array))
21
+
22
+ ==Todo
23
+
24
+ * Source documentation (rdoc)
25
+ * Fix limits/ known bugs
26
+ * Tests
27
+
28
+ ==Contributing
29
+
30
+ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
31
+ fix/feature has a high chance of being included, please read the following
32
+ guidelines:
33
+
34
+ 1. Fork the project.
35
+ 2. Make your feature addition or bug fix.
36
+ 3. Add tests for it. This is important so we don’t break anything in a future version unintentionally.
37
+ 4. 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)
38
+ 5. Send me a pull request. Bonus points for topic branches.
39
+
40
+
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 = 'sequel_column_type_array'
8
+ gem.authors = ['Corin Langosch']
9
+ gem.date = Date.today.to_s
10
+ gem.email = 'info@netskin.com'
11
+ gem.homepage = 'http://github.com/gucki/sequel_column_type_array'
12
+ gem.summary = 'Allow easy use of array column types with databases that support them'
13
+ gem.description = 'Handles the typecasting of array columns so they can be used as any other datatype.'
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "sequel_column_type_array #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,6 @@
1
+ require "sequel"
2
+ require "csv"
3
+
4
+ require "sequel_column_type_array/column_types"
5
+ require "sequel_column_type_array/dataset"
6
+ require "sequel_column_type_array/postgres"
@@ -0,0 +1,29 @@
1
+ module Sequel
2
+
3
+ class ColumnArray < Array
4
+ def normalize(data)
5
+ case data
6
+ when String
7
+ csv = data[1..-2]
8
+ csv.blank? ? [] : csv.parse_csv
9
+ when Array
10
+ data
11
+ else
12
+ raise ArgumentError, "unsupported input #{data}"
13
+ end
14
+ end
15
+ end
16
+
17
+ class IntegerColumnArray < ColumnArray
18
+ def initialize(data)
19
+ super(normalize(data).map{ |v| v.to_i })
20
+ end
21
+ end
22
+
23
+ class StringColumnArray < ColumnArray
24
+ def initialize(data)
25
+ super(normalize(data))
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,14 @@
1
+ module Sequel
2
+ class Dataset
3
+ def literal_array(v)
4
+ case v
5
+ when IntegerColumnArray
6
+ literal_string("{#{v*","}}")
7
+ when StringColumnArray
8
+ literal_string("{#{v.to_csv.strip}}")
9
+ else
10
+ Sequel.condition_specifier?(v) ? literal_expression(SQL::BooleanExpression.from_value_pairs(v)) : array_sql(v)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require "sequel/adapters/postgres"
2
+
3
+ module Sequel
4
+ module Postgres
5
+ PG_TYPES[1007] = lambda{ |s| IntegerColumnArray.new(s) } # integer[]
6
+ PG_TYPES[1014] = lambda{ |s| StringColumnArray.new(s) } # character[]
7
+ PG_TYPES[1015] = PG_TYPES[1014] # character varying[]
8
+
9
+ module DatabaseMethods
10
+ def schema_column_type(db_type)
11
+ type = super(db_type)
12
+ if db_type =~ /\[\]$/
13
+ type = "#{type}_array".to_sym
14
+ end
15
+ type
16
+ end
17
+
18
+ def typecast_value_integer_array(value)
19
+ IntegerColumnArray.new(value)
20
+ end
21
+
22
+ def typecast_value_string_array(value)
23
+ StringColumnArray.new(value)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,58 @@
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{sequel_column_type_array}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Corin Langosch"]
12
+ s.date = %q{2010-09-30}
13
+ s.description = %q{Handles the typecasting of array columns so they can be used as any other datatype.}
14
+ s.email = %q{info@netskin.com}
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/sequel_column_type_array.rb",
27
+ "lib/sequel_column_type_array/column_types.rb",
28
+ "lib/sequel_column_type_array/dataset.rb",
29
+ "lib/sequel_column_type_array/postgres.rb",
30
+ "sequel_column_type_array.gemspec",
31
+ "spec/sequel_colum_type_array.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/gucki/sequel_column_type_array}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Allow easy use of array column types with databases that support them}
40
+ s.test_files = [
41
+ "spec/spec_helper.rb",
42
+ "spec/sequel_colum_type_array.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SequelColumnTypeArray" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'sequel_column_type_array'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_column_type_array
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Corin Langosch
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Handles the typecasting of array columns so they can be used as any other datatype.
36
+ email: info@netskin.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/sequel_column_type_array.rb
52
+ - lib/sequel_column_type_array/column_types.rb
53
+ - lib/sequel_column_type_array/dataset.rb
54
+ - lib/sequel_column_type_array/postgres.rb
55
+ - sequel_column_type_array.gemspec
56
+ - spec/sequel_colum_type_array.rb
57
+ - spec/spec.opts
58
+ - spec/spec_helper.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/gucki/sequel_column_type_array
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Allow easy use of array column types with databases that support them
91
+ test_files:
92
+ - spec/spec_helper.rb
93
+ - spec/sequel_colum_type_array.rb