attribute_translator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in attribute_translator.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ attribute_translator (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ attribute_translator!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Artyom Bolshakov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Attribute translator
2
+
3
+ Translate model attribute values from locales.
4
+
5
+ ## Usage example
6
+
7
+ ```yaml
8
+ en.yml:
9
+ en:
10
+ activerecord:
11
+ values:
12
+ user:
13
+ state:
14
+ new: Just registered
15
+ ok: Active
16
+ ```
17
+
18
+ Modify ActiveRecord model:
19
+
20
+ ```ruby
21
+ class User < ActiveRecord::Base
22
+ translates :state
23
+ end
24
+ ```
25
+
26
+ Then:
27
+
28
+ ```ruby
29
+ user = User.first
30
+ user.state #=> "Just registered"
31
+ # To get original value use:
32
+ user.state_before_type_cast #=> "new"
33
+ ```
34
+
35
+ ## Installation
36
+
37
+ In Gemfile:
38
+
39
+ ```ruby
40
+ gem "attribute_translator"
41
+ ```
42
+
43
+ ## Copyright
44
+
45
+ Copyright (c) 2012 Artyom Bolshakov. See LICENSE for further details.
46
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "attribute_translator/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "attribute_translator"
7
+ s.version = AttributeTranslator::VERSION
8
+ s.authors = ["Artyom Balashov"]
9
+ # s.email = [""]
10
+ s.homepage = "http://github.com/bolshakov/attribute_translator"
11
+ s.summary = %q{Translate model attribute values from locales}
12
+ # s.description = %q{TODO: Write a gem description}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ # s.add_runtime_dependency "rest-client"
22
+ end
@@ -0,0 +1,5 @@
1
+ require "attribute_translator/version"
2
+ require "attribute_translator/active_record/base"
3
+
4
+ module AttributeTranslator
5
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveRecord
2
+ class Base
3
+ def self.translates(*attributes)
4
+ attributes.each do |attribute|
5
+ define_method attribute do
6
+ value = send("#{attribute}_before_type_cast")
7
+ begin
8
+ I18n.t(value, :scope => "activerecord.values.#{self.class.name.underscore}.#{attribute}")
9
+ rescue
10
+ value
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module AttributeTranslator
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attribute_translator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Artyom Balashov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-13 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - attribute_translator.gemspec
26
+ - lib/attribute_translator.rb
27
+ - lib/attribute_translator/active_record/base.rb
28
+ - lib/attribute_translator/version.rb
29
+ homepage: http://github.com/bolshakov/attribute_translator
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.10
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Translate model attribute values from locales
53
+ test_files: []