qui-common-helpers 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/qui-common-helpers.rb +18 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gemspec.email = "marcin@saepia.net"
|
10
10
|
gemspec.homepage = "http://q.saepia.net"
|
11
11
|
gemspec.authors = ["Marcin Lewandowski"]
|
12
|
-
gemspec.version = "0.0.
|
12
|
+
gemspec.version = "0.0.6"
|
13
13
|
gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*" ]
|
14
14
|
end
|
15
15
|
rescue LoadError
|
data/lib/qui-common-helpers.rb
CHANGED
@@ -40,17 +40,34 @@ module QUI
|
|
40
40
|
def self.included(base) # :nodoc:
|
41
41
|
base.extend ClassMethods
|
42
42
|
|
43
|
-
|
43
|
+
def link_default_description
|
44
44
|
if self.class.respond_to?(:link_default_description_field)
|
45
45
|
send(self.class.link_default_description_field)
|
46
46
|
else
|
47
47
|
"#{self.class.human_name} ##{id}"
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
def enum_human_value(attribute_name)
|
52
|
+
self.class.enum_human_value(attribute_name, self.send(attribute_name))
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
module ClassMethods
|
57
|
+
def is_enum?(attribute_name)
|
58
|
+
return false unless @enums
|
59
|
+
@enums.include? attribute_name.to_sym
|
60
|
+
end
|
61
|
+
|
62
|
+
def enum_human_value(attribute_name, value)
|
63
|
+
raise ArgumentError, "Attribute #{attribute_name} is not defined as enum with validates_enum_of" unless is_enum? attribute_name
|
64
|
+
|
65
|
+
I18n.t(:"activerecord.enums.#{self.to_s.tableize.singularize}.#{attribute_name}.#{value}")
|
66
|
+
end
|
67
|
+
|
53
68
|
def validates_enum_of(attribute_name)
|
69
|
+
@enums ||= []
|
70
|
+
@enums << attribute_name.to_sym
|
54
71
|
validates_inclusion_of attribute_name, :in => I18n.t("activerecord.enums.#{table_name.singularize}.#{attribute_name}").collect{|k,v| k.to_s.to_i }
|
55
72
|
end
|
56
73
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qui-common-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcin Lewandowski
|