marty 1.0.25 → 1.0.26

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: 5118b11e2b94fade41047bae2dec32b1a3bcd15a
4
- data.tar.gz: c022e1c2d19cdb84ca5403fc7898ebfeececaa88
3
+ metadata.gz: f67ebcac657138d046558974f9c05235794069e1
4
+ data.tar.gz: b79df0fe2a75a6a24e696a337db8799f2fbf57e1
5
5
  SHA512:
6
- metadata.gz: 51e55d9a99ddce93de589b4873005c337b7ad8343659d1b8771b65a2146b2da68fc5757668eb05a420b06d45f866c61f635932e57f7ca4f06e798d08d5154f98
7
- data.tar.gz: d097e901de04b56b8b073fb3e9459c952e7108f54261869c1e6501a56b4c473ef32793f4eae4deccf485f44ff92fcab6da79961af1737e8b69cf37a292da1029
6
+ metadata.gz: 804a7e3bb93f704897fd7773854487ab711a58c8f827acec33bc5a67eb9d2a4a54d33cd74277bbf115222541903ad9eac9bfe51e36933d83443bd501421699b8
7
+ data.tar.gz: e1637663e777a1fb8a2329446b7dc52a33ab79c26dd0830002a6da10b77b8872b9046dae5d053a052c478227fe403142a92ac9462d72621c80f4da2ae26a8633
@@ -1,11 +1,23 @@
1
1
  module Marty::PgEnum
2
+
2
3
  def [](index)
3
4
  index = index.to_s
4
5
 
5
6
  raise "no such #{self.name}: '#{index}'" unless
6
7
  self::VALUES.include?(index)
7
8
 
8
- index
9
+ StringEnum.new(index)
10
+ end
11
+
12
+ def get_all
13
+ self::VALUES.map { |v| StringEnum.new(v) }
14
+ end
15
+
16
+ GET_ALL_SIG = [0, 0]
17
+ def self.extended(base)
18
+ base.class_eval do
19
+ const_set :GET_ALL_SIG, Marty::PgEnum::GET_ALL_SIG
20
+ end
9
21
  end
10
22
 
11
23
  alias_method :find_by_name, :[]
@@ -80,10 +80,16 @@ class Marty::DataExporter
80
80
  end
81
81
  end
82
82
 
83
+ def self.get_attrs_in_order(klass, attrs)
84
+ return attrs unless klass.const_defined?(:EXPORT_ORDER)
85
+ klass::EXPORT_ORDER.select { |attr| attrs.include?(attr) }
86
+ end
87
+
83
88
  def self.export_attrs(klass, obj, attrs=nil, exclude_attrs=[])
84
89
  col_types = Marty::DataConversion.col_types(klass)
85
90
 
86
- attr_list = (attrs || col_types.keys).map(&:to_s) - exclude_attrs
91
+ attr_list_raw = (attrs || col_types.keys).map(&:to_s) - exclude_attrs
92
+ attr_list = get_attrs_in_order(klass, attr_list_raw)
87
93
 
88
94
  attr_list.map do
89
95
  |c|
@@ -111,7 +117,8 @@ class Marty::DataExporter
111
117
  def self.export_headers(klass, attrs=nil, exclude_attrs=[])
112
118
  col_types = Marty::DataConversion.col_types(klass)
113
119
 
114
- attr_list = (attrs || col_types.keys).map(&:to_s) - exclude_attrs
120
+ attr_list_raw = (attrs || col_types.keys).map(&:to_s) - exclude_attrs
121
+ attr_list = get_attrs_in_order(klass, attr_list_raw)
115
122
 
116
123
  attr_list.map do
117
124
  |c|
@@ -10,7 +10,8 @@ class Delorean::BaseModule::BaseClass
10
10
  alias_method :old_get_attr, :_get_attr
11
11
 
12
12
  def _get_attr(obj, attr, _e)
13
- if Marty::Enum === obj && !obj.respond_to?(attr)
13
+ if (Marty::Enum === obj ||
14
+ Marty::PgEnum === obj) && !obj.respond_to?(attr)
14
15
  obj[attr]
15
16
  else
16
17
  old_get_attr(obj, attr, _e)
@@ -114,6 +115,7 @@ class String
114
115
  def in_time_zone(zone = ::Time.zone)
115
116
  self == 'infinity' ? self : old_in_time_zone(zone)
116
117
  end
118
+
117
119
  end
118
120
 
119
121
  ######################################################################
@@ -197,6 +199,18 @@ module Netzke::Basepack::DataAdapters
197
199
  end
198
200
  end
199
201
 
202
+ class StringEnum < String
203
+ include Delorean::Model
204
+ def name
205
+ self
206
+ end
207
+ def id
208
+ self
209
+ end
210
+ delorean_instance_method :name
211
+ delorean_instance_method :id
212
+ end
213
+
200
214
  ######################################################################
201
215
 
202
216
  # Add pg_enum migration support -- FIXME: this doesn't belong here
@@ -209,5 +223,14 @@ module ActiveRecord
209
223
  column_names.each { |name| column(name, name.to_s.pluralize, options) }
210
224
  end
211
225
  end
226
+ module PostgreSQL
227
+ module OID
228
+ class Enum < Type::Value
229
+ def type_cast_from_database(value)
230
+ value && StringEnum.new(value)
231
+ end
232
+ end
233
+ end
234
+ end
212
235
  end
213
236
  end
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "1.0.25"
2
+ VERSION = "1.0.26"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.25
4
+ version: 1.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2017-04-20 00:00:00.000000000 Z
17
+ date: 2017-05-03 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: pg