sql_enum 0.1.1 → 0.1.2

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: 91024ad7ccdb1b3b159c67f76dccc9682a8057c4
4
- data.tar.gz: 3c65cc103e2e53eddc9c7f60c7a8bb698d10fba5
3
+ metadata.gz: 8e66d89471635b35ba4a82a44cbdba443120926c
4
+ data.tar.gz: bc24ffca63ef8480683d5bed1027a5104d23d94b
5
5
  SHA512:
6
- metadata.gz: 6e35eb50be5ed87033e42f4932d95837b770c6870ed8c1b27d77c2f8cccbe1c695aee4d5c0784b91afda2e34371c1e598b14280cde49801fc0bfb296719b10ed
7
- data.tar.gz: db9b719cfa23bb8c2a2175f6851f13bc7a3c83d085b3f4da03b800acb808ed4be3882d8f1d687b2d0091143e36b0a45cb412882f976426ac5e4c6098a69575a2
6
+ metadata.gz: 0e8faa146d9d0b72b09e2822834659ff1c4c1ddbb80175b226df6df923603f1fb02eaa678af4b044887d12a31b03cfaaf4d275f9f7b2d275c1212c50efd27521
7
+ data.tar.gz: 46a7a0b34a9aaeddf20016745c4dd2d73e02005bc1a4ea1bb6e7ce05094ead55c0509bb7f945548b121a608e1ac73fc2f5f7c08fc401ccf20372e45eb9c07ae6
@@ -20,7 +20,7 @@ module ActiveRecord
20
20
  end
21
21
 
22
22
  def deserialize(value)
23
- value
23
+ value&.to_sym
24
24
  end
25
25
 
26
26
  def serialize(value)
@@ -5,6 +5,10 @@ module ActiveRecord
5
5
  def sql_enum(name, options={})
6
6
  enum_prefix = options.delete(:_prefix)
7
7
  enum_suffix = options.delete(:_suffix)
8
+
9
+ enum_prefix ||= name if SqlEnum.configuration.default_prefix
10
+ enum_suffix ||= name if SqlEnum.configuration.default_suffix
11
+
8
12
  klass = self
9
13
  enum_values = Array.new
10
14
  name = name.to_sym
@@ -37,7 +41,7 @@ module ActiveRecord
37
41
 
38
42
  # def active?() status == 0 end
39
43
  klass.send(:detect_enum_conflict!, name, "#{value_method_name}?")
40
- define_method("#{value_method_name}?") { self[attr] == value.to_s }
44
+ define_method("#{value_method_name}?") { binding.pry; self[attr] == value.to_s }
41
45
 
42
46
  # def active!() update! status: :active end
43
47
  klass.send(:detect_enum_conflict!, name, "#{value_method_name}!")
@@ -1,3 +1,3 @@
1
1
  module SqlEnum
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/sql_enum.rb CHANGED
@@ -9,4 +9,21 @@ require_relative 'active_record/connection_adapters/mysql/column_methods'
9
9
  require_relative "sql_enum/version"
10
10
 
11
11
  module SqlEnum
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configure
17
+ self.configuration ||= Configuration.new
18
+ yield(configuration)
19
+ end
20
+
21
+ class Configuration
22
+ attr_accessor :default_prefix, :default_suffix
23
+
24
+ def initialize
25
+ @default_prefix = false
26
+ @default_suffix = false
27
+ end
28
+ end
12
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Fowler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-27 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord