restpack_service 0.0.43 → 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43532f12d0afd4a04e3d35b9bb5f8cb67defd30d
4
- data.tar.gz: a03b62a4097ed6942428ba47db599561940e5aae
3
+ metadata.gz: b27c8ec0fbdf8d91aa162da9084cf73837c858f2
4
+ data.tar.gz: 47be98d7cce1b9af19a81d1d6be17c8aaf9125aa
5
5
  SHA512:
6
- metadata.gz: 85e71bd8f1a1bcb5c36c9aa9e927809eb77bfc8dadf5e29a83e742e1e035e557561e065b6fc83a25131540b9bf947474ca1ba79c0d0062b13c77d8fa69ec2460
7
- data.tar.gz: 9bcda2381baf9e0336bb670619dfa9a0514eb7ed37e85cfc92958b47d1797b0f22a6be0e207ce1c763a77f32d80eba6350e53613e28e06e61a34fa8e0eba5430
6
+ metadata.gz: 1eedb5d7ef19f0232ca912dd94b40117b9ffeef26c5469900f40435ec4a31a1a683c8d195b4c9a6cb0dbac8650f009cfb196f059d81ed940b7d92820abd2b49b
7
+ data.tar.gz: 9ee43d62fabadc1d93b635aef539b5e03a143074f713d7be3bca78df82303d103e8c642b292f9f405ee1cb079d313ba700d11b40e4eeff71a52545308bc72df9
@@ -0,0 +1,121 @@
1
+ #http://stackoverflow.com/questions/17385023/cant-store-array-in-json-field-in-postgresql-rails-cant-cast-array-to-json
2
+ require 'active_record'
3
+ require 'active_record/connection_adapters/postgresql/cast'
4
+ module ActiveRecord::ConnectionAdapters::PostgreSQLColumn::Cast
5
+ def json_to_string(object)
6
+ if Hash === object || Array === object
7
+ ActiveSupport::JSON.encode(object)
8
+ else
9
+ object
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'active_record/connection_adapters/postgresql/quoting'
15
+ module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Quoting
16
+ def quote(value, column = nil) #:nodoc:
17
+ return super unless column
18
+
19
+ sql_type = type_to_sql(column.type, column.limit, column.precision, column.scale)
20
+
21
+ case value
22
+ when Range
23
+ if /range$/ =~ sql_type
24
+ "'#{ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string(value)}'::#{sql_type}"
25
+ else
26
+ super
27
+ end
28
+ when Array
29
+ case sql_type
30
+ when 'point' then super(ActiveRecord::ConnectionAdapters::PostgreSQLColumn.point_to_string(value))
31
+ when 'json' then super(ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value))
32
+ else
33
+ if column.array
34
+ "'#{ActiveRecord::ConnectionAdapters::PostgreSQLColumn.array_to_string(value, column, self).gsub(/'/, "''")}'"
35
+ else
36
+ super
37
+ end
38
+ end
39
+ when Hash
40
+ case sql_type
41
+ when 'hstore' then super(ActiveRecord::ConnectionAdapters::PostgreSQLColumn.hstore_to_string(value), column)
42
+ when 'json' then super(ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value), column)
43
+ else super
44
+ end
45
+ when IPAddr
46
+ case sql_type
47
+ when 'inet', 'cidr' then super(ActiveRecord::ConnectionAdapters::PostgreSQLColumn.cidr_to_string(value), column)
48
+ else super
49
+ end
50
+ when Float
51
+ if value.infinite? && column.type == :datetime
52
+ "'#{value.to_s.downcase}'"
53
+ elsif value.infinite? || value.nan?
54
+ "'#{value.to_s}'"
55
+ else
56
+ super
57
+ end
58
+ when Numeric
59
+ if sql_type == 'money' || [:string, :text].include?(column.type)
60
+ # Not truly string input, so doesn't require (or allow) escape string syntax.
61
+ "'#{value}'"
62
+ else
63
+ super
64
+ end
65
+ when String
66
+ case sql_type
67
+ when 'bytea' then "'#{escape_bytea(value)}'"
68
+ when 'xml' then "xml '#{quote_string(value)}'"
69
+ when /^bit/
70
+ case value
71
+ when /^[01]*$/ then "B'#{value}'" # Bit-string notation
72
+ when /^[0-9A-F]*$/i then "X'#{value}'" # Hexadecimal notation
73
+ end
74
+ else
75
+ super
76
+ end
77
+ else
78
+ super
79
+ end
80
+ end
81
+
82
+ def type_cast(value, column, array_member = false)
83
+ return super(value, column) unless column
84
+
85
+ case value
86
+ when Range
87
+ return super(value, column) unless /range$/ =~ column.sql_type
88
+ ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string(value)
89
+ when NilClass
90
+ if column.array && array_member
91
+ 'NULL'
92
+ elsif column.array
93
+ value
94
+ else
95
+ super(value, column)
96
+ end
97
+ when Array
98
+ case column.sql_type
99
+ when 'point' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.point_to_string(value)
100
+ when 'json' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value)
101
+ else
102
+ return super(value, column) unless column.array
103
+ ActiveRecord::ConnectionAdapters::PostgreSQLColumn.array_to_string(value, column, self)
104
+ end
105
+ when String
106
+ return super(value, column) unless 'bytea' == column.sql_type
107
+ { :value => value, :format => 1 }
108
+ when Hash
109
+ case column.sql_type
110
+ when 'hstore' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.hstore_to_string(value)
111
+ when 'json' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value)
112
+ else super(value, column)
113
+ end
114
+ when IPAddr
115
+ return super(value, column) unless ['inet','cidr'].include? column.sql_type
116
+ ActiveRecord::ConnectionAdapters::PostgreSQLColumn.cidr_to_string(value)
117
+ else
118
+ super(value, column)
119
+ end
120
+ end
121
+ end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.43"
3
+ VERSION = "0.0.44"
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ require "restpack_service/activerecord/postgres_array_patch"
2
+
1
3
  require "mutations"
2
4
  require "yajl"
3
5
  require "protected_attributes"
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "mutations", "~> 0.6.0"
22
22
  spec.add_dependency "yajl-ruby", "~> 1.1.0"
23
- spec.add_dependency "restpack_gem", "~> 0.0.8"
24
23
  spec.add_dependency "protected_attributes", "~> 1.0.3"
25
24
  spec.add_dependency "require_all", "~> 1.3.0"
26
25
  spec.add_dependency "restpack_serializer"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.43
4
+ version: 0.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.0
41
- - !ruby/object:Gem::Dependency
42
- name: restpack_gem
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: 0.0.8
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.0.8
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: protected_attributes
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +193,7 @@ files:
207
193
  - README.md
208
194
  - Rakefile
209
195
  - lib/restpack_service.rb
196
+ - lib/restpack_service/activerecord/postgres_array_patch.rb
210
197
  - lib/restpack_service/command.rb
211
198
  - lib/restpack_service/configuration.rb
212
199
  - lib/restpack_service/loader.rb