Skip to content
Browse files

Merge remote-tracking branch 'divineforest/master'

  • Loading branch information...
2 parents 4357d77 + f90f56f commit 16dc655ce68a3659e838832c7f1f4fac40dae8b8 @divineforest divineforest committed May 15, 2012
Showing with 51 additions and 30 deletions.
  1. +41 −0 README.md
  2. +0 −28 README.rdoc
  3. +9 −1 lib/human_attribute/active_record/base.rb
  4. +1 −1 lib/human_attribute/version.rb
View
41 README.md
@@ -0,0 +1,41 @@
+# Human Attribute
+
+1. Defines method "human_name" for attribute name translation;
+1. Defines method "human_value" for attribute value translation.
+
+## Usage example
+
+```yaml
+en.yml:
+ en
+ activerecord
+ attributes:
+ user:
+ state: Status
+ attribute_values:
+ user:
+ state:
+ new: Just registered
+ ok: Active
+```
+
+Then:
+
+```ruby
+ user = User.first
+ user.state # => "new"
+ user.human_name(:state) # => "Status"
+ user.human_value(:state) # => "Just registered"
+```
+
+## Installation
+
+In Gemfile:
+
+```ruby
+ gem 'human_attribute'
+```
+
+## Copyright
+
+Copyright (c) 2012 divineforest, [Evrone.com](http://evrone.com)
View
28 README.rdoc
@@ -1,28 +0,0 @@
-= Human Attribute
-
-Defines method "human_value" for attribute translation.
-
-= Usage example
-
-en.yml:
- en
- activerecord
- attribute_values:
- user:
- state:
- new: Just registered
- ok: Active
-
-Then:
- user = User.first
- user.state # => "new"
- user.human_value(:state) # => "Just registered"
-
-= Installation
-
-In Gemfile:
- gem 'human_attribute'
-
-== Copyright
-
-Copyright (c) 2011 divineforest, {Evrone.com}[http://evrone.com]
View
10 lib/human_attribute/active_record/base.rb
@@ -1,10 +1,18 @@
module ActiveRecord
class Base
+ # Looks in en.activerecord.attributes.class.attribute_name
+ # Example I18n lookup: en.activerecord.attributes.user.state
+ def human_name(attribute_name)
+ self.class.human_attribute_name(attribute_name)
+ end
+
+ # en.activerecord.attribute_values.class_name.attribute_name
+ # Example I18n lookup: en.activerecord.attribute_values.user.state
def human_value(attribute_name)
value = send(attribute_name)
if value.present?
- I18n.t(value, :scope => "activerecord.attribute_values.#{self.class.name.downcase}.#{attribute_name}")
+ I18n.t(value, :scope => "activerecord.attribute_values.#{self.class.name.underscore}.#{attribute_name}")
else
value
end
View
2 lib/human_attribute/version.rb
@@ -1,3 +1,3 @@
module HumanAttribute
- VERSION = "0.0.2"
+ VERSION = "0.2.0"
end

0 comments on commit 16dc655

Please sign in to comment.
Something went wrong with that request. Please try again.