enumerated_attr 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/enumerated_attr.rb +19 -13
- data/lib/enumerated_attr/version.rb +1 -1
- metadata +3 -24
data/lib/enumerated_attr.rb
CHANGED
@@ -2,29 +2,35 @@ require 'i18n'
|
|
2
2
|
require 'active_support/inflector'
|
3
3
|
|
4
4
|
module EnumeratedAttr
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
5
|
+
class Attribute
|
6
|
+
def initialize(klass, attribute, enumeration)
|
7
|
+
@klass = klass
|
8
|
+
@attribute = attribute.to_sym
|
9
|
+
@enumeration = enumeration
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
12
|
+
def human(value)
|
13
|
+
klass_name = @klass.name.underscore
|
14
|
+
I18n.t :"enumerations.#{klass_name}.#{@attribute}.#{value}", :default => value.to_s.humanize
|
15
|
+
end
|
16
|
+
|
17
|
+
def enumeration
|
18
|
+
@enumeration.map do |value|
|
19
|
+
[human(value), value]
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
24
|
module Glue
|
19
25
|
def enumerated_attr(attribute, enumeration, options = {})
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
enum = Attribute.new(self, attribute, enumeration)
|
27
|
+
|
28
|
+
define_method "human_#{attribute}_value" do |value = false|
|
29
|
+
enum.human(value || self.send(attribute))
|
23
30
|
end
|
24
31
|
|
25
|
-
#
|
26
|
-
|
27
|
-
Base.enumeration(self.class, attribute, enumeration)
|
32
|
+
define_singleton_method "#{attribute}_enumeration" do
|
33
|
+
enum.enumeration
|
28
34
|
end
|
29
35
|
|
30
36
|
if options[:validates]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerated_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: pry
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
description: A very simple enumeration gem
|
63
47
|
email: lenon.marcel@gmail.com
|
64
48
|
executables: []
|
@@ -79,18 +63,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
63
|
- - ! '>='
|
80
64
|
- !ruby/object:Gem::Version
|
81
65
|
version: '0'
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
hash: -4522294971138115199
|
85
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
67
|
none: false
|
87
68
|
requirements:
|
88
69
|
- - ! '>='
|
89
70
|
- !ruby/object:Gem::Version
|
90
71
|
version: '0'
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
hash: -4522294971138115199
|
94
72
|
requirements: []
|
95
73
|
rubyforge_project:
|
96
74
|
rubygems_version: 1.8.24
|
@@ -98,3 +76,4 @@ signing_key:
|
|
98
76
|
specification_version: 3
|
99
77
|
summary: EnumeratedAttr
|
100
78
|
test_files: []
|
79
|
+
has_rdoc:
|