platanus 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/platanus/enum.rb +12 -0
- data/lib/platanus/version.rb +1 -1
- metadata +2 -2
data/lib/platanus/enum.rb
CHANGED
@@ -68,6 +68,18 @@ module Platanus
|
|
68
68
|
raise InvalidEnumName
|
69
69
|
end
|
70
70
|
|
71
|
+
# Retrieve singleton class to define new class methods
|
72
|
+
klass = class << self; self; end
|
73
|
+
|
74
|
+
# Add parse function
|
75
|
+
klass.send(:define_method, 'parse_' + _target.to_s) do |value|
|
76
|
+
value = value.to_s
|
77
|
+
map.each_pair do |k,v|
|
78
|
+
return k if v == value
|
79
|
+
end
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
|
71
83
|
# Add value validator (unless validation is disabled)
|
72
84
|
self.validates _target, inclusion: { :in => map.keys } if _options.fetch(:validate, true)
|
73
85
|
end
|
data/lib/platanus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platanus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Platan.us utility gem
|
15
15
|
email:
|