pg_adaptor 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfc0dcf438e8dc8789592286681dd3632eba37e4
4
- data.tar.gz: 774023af3f1687f52b4d3fe24770d9d646f48bee
3
+ metadata.gz: 7a8ffe15c8a5d554cc272a46dcfc60a113086965
4
+ data.tar.gz: 43493eeae64eb8c2f0abd636ade6f11bfd18ef61
5
5
  SHA512:
6
- metadata.gz: f4a377451cb5b9f7f1ba2d5281f1892e35b7f4773948de9a0e6b73e582d3345e80f64561cae100288671c8c60a6b4a6800ac0eff16f013a1bc5f42fbdaab9ae2
7
- data.tar.gz: 07bc7152820473c410fe86e436502576a95f440e04e807918d7cb6742b68ec3aa5bef627cc2849ff1565419ac2b50d2cedf5d83e1ebc7b151cf1b38bb8068edb
6
+ metadata.gz: 91a67fb757367fb7080da42c74db0078a968849734d5aa7127c2967af66bc9d789cad9cb51e65bbb92f02a2945d1570ea76fe2e1caec2524ce050c354b96bf3a
7
+ data.tar.gz: 5cf92939e51b66fa0da5bb66a16170e6c538f0a6ad0ca1de5d9252b6f9acf14d5aa18ee2f57d03c8a9382f4869b46803d71b4a16037ceed8ea610d52ff824cea
@@ -1,3 +1,3 @@
1
1
  class PGAdaptor
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/pg_adaptor.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'sequel'
2
+ require 'json'
2
3
  require "pg_adaptor/version"
3
4
 
4
5
  class PGAdaptor
@@ -45,16 +46,23 @@ private
45
46
  end
46
47
  end
47
48
 
49
+ def schema
50
+ @schema ||=
51
+ begin
52
+ schema = {}
53
+ self.class.db.schema(@name).each do |(key, info)|
54
+ schema[key] = info
55
+ end
56
+ schema
57
+ end
58
+ end
59
+
48
60
  def process(model)
49
- schema = {}
50
- self.class.db.schema(@name).each do |(key, info)|
51
- schema[key] = info
52
- end
53
61
  fields = {}
54
62
  model.each_pair do |field,value|
55
63
  next if field == :id && value.nil?
56
- raise "Field not present in schema: #{field}" unless schema[field]
57
- case schema[field][:db_type]
64
+ raise "Field not present in schema: #{field}" unless schema[field.to_sym]
65
+ case schema[field.to_sym][:db_type]
58
66
  when "jsonb" then fields[field] = Sequel.pg_jsonb value
59
67
  when /\[\]$/ then fields[field] = Sequel.pg_array value
60
68
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_adaptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Rowe