enum_attr 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/enum_attr.gemspec +1 -1
  3. data/lib/enum_attr.rb +6 -0
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/enum_attr.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{enum_attr}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["qichunren"]
data/lib/enum_attr.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module EnumAttr
2
4
  module Mixin
3
5
  # for model Contract:
@@ -46,6 +48,10 @@ ENUMS_#{attr.upcase} = enums.collect{|item| [item[0], item[1]]}
46
48
 
47
49
  validates_inclusion_of attr, :in => enums.map{|e| e[1].to_i}, :allow_nil => true
48
50
 
51
+ def self.#{attr}_name_by(arg)
52
+ ENUMS_#{attr.upcase}.find{|option| option[1] == arg }[0]
53
+ end
54
+
49
55
  def #{attr}_name
50
56
  ENUMS_#{attr.upcase}.find{|option| option[1] == #{attr}}[0] unless #{attr}.nil?
51
57
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - qichunren