ar_pg_array 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activerecord", ">= 3.0.6", "< 4.0"
4
+ group :development, :test do
5
+ gem "cancan"
6
+ gem "pg"
7
+ gem "rspec"
8
+ end
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
2
+ require 'rdoc/task'
7
3
 
8
4
  desc 'Test the postgres_arrays plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
5
+ task :test do
6
+ Dir.chdir(File.dirname(__FILE__)) do
7
+ Process.wait2 spawn('rspec spec')
8
+ end
9
+ end
10
+
11
+ task :default do
12
+ # nothing
13
13
  end
14
14
 
15
15
  desc 'Generate documentation for the postgres_arrays plugin.'
@@ -20,24 +20,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('README')
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |gemspec|
27
- gemspec.name = "ar_pg_array"
28
- gemspec.summary = "Use power of PostgreSQL Arrays in ActiveRecord"
29
- gemspec.description = "ar_pg_array includes support of PostgreSQL's int[], float[], text[], timestamptz[] etc. into ActiveRecord. You could define migrations for array columns, query on array columns."
30
- gemspec.email = "funny.falcon@gmail.com"
31
- gemspec.homepage = "http://github.com/funny-falcon/activerecord-postgresql-arrays"
32
- gemspec.authors = ["Sokolov Yura aka funny_falcon"]
33
- gemspec.add_dependency('activerecord', '>= 3.0.6', '<4.0')
34
- gemspec.rubyforge_project = 'ar-pg-array'
35
- end
36
- Jeweler::GemcutterTasks.new
37
- Jeweler::RubyforgeTasks.new do |rubyforge|
38
-
39
- end
40
- rescue LoadError
41
- puts "Jeweler not available. Install it with: gem install jeweler"
42
- end
43
-
@@ -0,0 +1,34 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ar_pg_array"
8
+ s.version = "0.11.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sokolov Yura aka funny_falcon"]
12
+ s.date = "2012-06-03"
13
+ s.description = "ar_pg_array includes support of PostgreSQL's int[], float[], text[], timestamptz[] etc. into ActiveRecord. You could define migrations for array columns, query on array columns."
14
+ s.email = "funny.falcon@gmail.com"
15
+ s.extra_rdoc_files = [ "README" ]
16
+ s.files = (Dir['lib/**/*']+Dir['spec/**/*']+%w{Gemfile init.rb MIT_LICENSE README Rakefile ar_pg_array.gemspec}).find_all{|f| File.file?(f)}
17
+ s.homepage = "http://github.com/funny-falcon/activerecord-postgresql-arrays"
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = "ar-pg-array"
20
+ s.summary = "Use power of PostgreSQL Arrays in ActiveRecord"
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<activerecord>, ["< 4.0", ">= 3.0.6"])
27
+ else
28
+ s.add_dependency(%q<activerecord>, ["< 4.0", ">= 3.0.6"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<activerecord>, ["< 4.0", ">= 3.0.6"])
32
+ end
33
+ end
34
+
@@ -76,6 +76,8 @@ if ActiveRecord::VERSION::STRING < '3.1'
76
76
  attribute.ar_all(value)
77
77
  when PGArrays::PgIncludes
78
78
  attribute.ar_included(value)
79
+ when PGArrays::PgArray
80
+ attribute.eq(value)
79
81
  when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
80
82
  values = value.to_a.map { |x|
81
83
  x.is_a?(ActiveRecord::Base) ? x.id : x
@@ -125,6 +127,8 @@ else
125
127
  attribute.ar_all(value)
126
128
  when PGArrays::PgIncludes
127
129
  attribute.ar_included(value)
130
+ when PGArrays::PgArray
131
+ attribute.eq(value)
128
132
  when ActiveRecord::Relation
129
133
  value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty?
130
134
  attribute.in(value.arel.ast)
@@ -227,6 +227,17 @@ module ActiveRecord
227
227
  end
228
228
 
229
229
  alias_method_chain :type_to_sql, :postgresql_arrays
230
+
231
+ if method_defined?(:type_cast)
232
+ def type_cast_with_postgresql_arrays(value, column)
233
+ if Array === value && column && "#{column.type}" =~ /^(.+)_array$/
234
+ prepare_array_for_arel_by_base_type(value, $1)
235
+ else
236
+ type_cast_without_postgresql_arrays(value, column)
237
+ end
238
+ end
239
+ alias_method_chain :type_cast, :postgresql_arrays
240
+ end
230
241
  end
231
242
  end
232
243
  end
@@ -1,2 +1,5 @@
1
1
  class Bulk < ActiveRecord::Base
2
2
  end
3
+
4
+ class Bulk1 < Bulk
5
+ end
@@ -28,6 +28,7 @@ fourth:
28
28
  decimals: [ ]
29
29
  fifth:
30
30
  id: 5
31
+ type: "Bulk1"
31
32
  ints: [ 10 ]
32
33
  strings: [ "#{1+1}", "\\#{1+1}\"'\\z\x01", "\t\n" ]
33
34
  times: [ ]
@@ -12,6 +12,7 @@ ActiveRecord::Schema.define do
12
12
  end
13
13
 
14
14
  create_table "bulks", :force => true do |t|
15
+ t.string :type, :default => "Bulk"
15
16
  t.string :value, :default => "'"
16
17
  t.integer_array :ints, :default => [1, 2]
17
18
  t.string_array :strings, :default => %w{as so}
@@ -72,7 +72,7 @@ describe "PgArray" do
72
72
  bulk.floats.should == [1.0, 2.3]
73
73
  bulk.decimals.should == [1.0, 2.3]
74
74
  end
75
-
75
+
76
76
  it "should be created with defaults" do
77
77
  bulk = Bulk.new
78
78
  bulk.ints.should == [1, 2]
@@ -84,6 +84,12 @@ describe "PgArray" do
84
84
  map_times(parse_times(%w{2010-01-01 2010-02-01}))
85
85
  end
86
86
 
87
+ it "should be able to insert" do
88
+ bulk = Bulk.new
89
+ bulk.save
90
+ bulk.destroy
91
+ end
92
+
87
93
  it "should not alter defaults" do
88
94
  bulk = Bulk.new
89
95
  bulk.strings.push :foo
@@ -192,6 +198,19 @@ describe "PgArray" do
192
198
  model2.for_custom_serialize.to_yaml.should == obj.to_yaml
193
199
  end
194
200
 
201
+ it 'should be workable with sti' do
202
+ obj = Bulk1.where(:ints => [10].pg).first
203
+ obj.should be_instance_of Bulk1
204
+ obj.floats = [1.1, 2.2]
205
+ obj.save
206
+ obj1 = Bulk.find(obj.id)
207
+ obj1.should be_instance_of Bulk1
208
+ obj1.floats.should == [1.1, 2.2]
209
+ obj2 = Bulk1.new
210
+ obj2.save
211
+ obj2.destroy
212
+ end
213
+
195
214
  def map_times(times)
196
215
  times.map{|t| t.strftime("%F %T")}
197
216
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_pg_array
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -42,33 +42,33 @@ extensions: []
42
42
  extra_rdoc_files:
43
43
  - README
44
44
  files:
45
- - MIT-LICENSE
46
- - README
47
- - Rakefile
48
- - VERSION
49
- - init.rb
50
45
  - lib/ar_pg_array.rb
51
- - lib/ar_pg_array/allways_save.rb
52
- - lib/ar_pg_array/parser.rb
53
- - lib/ar_pg_array/querying.rb
54
46
  - lib/ar_pg_array/querying_arel.rb
47
+ - lib/ar_pg_array/schema_cacheable.rb
55
48
  - lib/ar_pg_array/references_by.rb
56
- - lib/ar_pg_array/schema.rb
57
49
  - lib/ar_pg_array/schema_arel.rb
58
- - lib/ar_pg_array/schema_cacheable.rb
50
+ - lib/ar_pg_array/querying.rb
51
+ - lib/ar_pg_array/allways_save.rb
59
52
  - lib/ar_pg_array/schema_fix_will_change.rb
60
- - spec/fixtures/bulk.rb
53
+ - lib/ar_pg_array/parser.rb
54
+ - lib/ar_pg_array/schema.rb
55
+ - spec/spec_helper.rb
56
+ - spec/spec.opts
61
57
  - spec/fixtures/bulks.yml
62
- - spec/fixtures/item.rb
58
+ - spec/fixtures/tags.yml
59
+ - spec/fixtures/unrelateds.yml
60
+ - spec/fixtures/tag.rb
63
61
  - spec/fixtures/items.yml
62
+ - spec/fixtures/item.rb
64
63
  - spec/fixtures/schema.rb
65
- - spec/fixtures/tag.rb
66
- - spec/fixtures/tags.yml
64
+ - spec/fixtures/bulk.rb
67
65
  - spec/fixtures/unrelated.rb
68
- - spec/fixtures/unrelateds.yml
69
66
  - spec/pg_array_spec.rb
70
- - spec/spec.opts
71
- - spec/spec_helper.rb
67
+ - Gemfile
68
+ - init.rb
69
+ - README
70
+ - Rakefile
71
+ - ar_pg_array.gemspec
72
72
  homepage: http://github.com/funny-falcon/activerecord-postgresql-arrays
73
73
  licenses: []
74
74
  post_install_message:
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010 Sokolov Yura aka funny_falcon
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/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.11.0