i18n_accessors 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2641f6115e4fbd623fab985ebc188a1881350204
4
- data.tar.gz: 24a1d8811112f7a4c449eecd8c0ea44e7e41e972
3
+ metadata.gz: 98b58932586d8b91f258b71fb586f16caad57ecd
4
+ data.tar.gz: 11a1f04242c82616d1a94fdad70cc174bd77f65e
5
5
  SHA512:
6
- metadata.gz: 1e2ee6e8e13756ea930fffb422c65d267c018650f2fdeeca67d8703355b199397df0c5d97d13a252093ca0afd47432b14c232a5dbc3d3988fc90bfda6620c5ce
7
- data.tar.gz: ac83bff33d37df96709c92f2658c27fdc8852851797128ae3747a4132aeb62d92999ac2749364bcdc86d1fdc6e7546aa414c256c46704590b79a3ef783fc2899
6
+ metadata.gz: d9aa04edf966a12cfbadc3ffb46c790900904847b66b06b55243a3cf0a4b0c9e4024113d4f9b2af24f067dd0d013421c59b6cafbdda11961b312244ba4598da4
7
+ data.tar.gz: a2076b293ec651056c1e2a152d90809b870139f34b18df74ddfd85bdbba0986b742b106a337c58ca2f5b419224a52a87e0dbaa919108307082dc8c06a91e81fc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_accessors (0.1.0)
4
+ i18n_accessors (0.1.1)
5
5
  i18n (>= 0.6.10, < 0.9)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -6,14 +6,16 @@
6
6
  [gem]: https://rubygems.org/gems/i18n_accessors
7
7
  [travis]: https://travis-ci.org/shioyama/i18n_accessors
8
8
 
9
- Define locale accessors for your translated attributes.
9
+ Define locale accessors for your translated attributes. Extracted from
10
+ [Mobility](https://github.com/shioyama/mobility); works with
11
+ [Globalize](https://github.com/globalize/globalize) and other translation gems.
10
12
 
11
13
  ## Installation
12
14
 
13
15
  Add this line to your application's Gemfile:
14
16
 
15
17
  ```ruby
16
- gem 'i18n_accessors', '~> 0.1.1'
18
+ gem 'i18n_accessors', '~> 0.1.2'
17
19
  ```
18
20
 
19
21
  And then execute:
@@ -45,7 +47,7 @@ class Post
45
47
 
46
48
  def title=(title)
47
49
  # ...
48
- end
50
+ end
49
51
 
50
52
  include I18nAccessors::Methods.new(:title)
51
53
  end
@@ -87,7 +89,23 @@ class Post
87
89
  end
88
90
  ```
89
91
 
90
- No options are accepted to the constructor for this class.
92
+ You can include both a `I18nAccessors::Methods` module and a
93
+ `I18nAccessors::Missing` module in the same class without conflict (the
94
+ accessor methods will take precedence).
95
+
96
+ ### Configuration
97
+
98
+ If you are using I18nAccessors with Globalize, you can change the default i18n
99
+ class to `Globalize`:
100
+
101
+ ```ruby
102
+ I18nAccessors.configure do |config|
103
+ config.i18n_class = Globalize
104
+ end
105
+ ```
106
+
107
+ With this configuration, `Globalize.with_locale` will be used to set the locale
108
+ around the accessor methods, rather than `I18n.with_locale`.
91
109
 
92
110
  ## Development
93
111
 
@@ -4,6 +4,24 @@ require "i18n_accessors/missing"
4
4
 
5
5
  module I18nAccessors
6
6
  class << self
7
+
8
+ # Configure I18nAccessors
9
+ # @yield [I18nAccessors::Configuration] I18nAccessors configuration
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ # @!group Configuration Methods
15
+ # @return [I18nAccessors::Configuration] I18nAccessors configuration
16
+ def config
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ # @return [Class] I18n Class to use for setting locale
21
+ def i18n_class
22
+ config.i18n_class
23
+ end
24
+
7
25
  # Return normalized locale
8
26
  # @param [String,Symbol] locale
9
27
  # @return [String] Normalized locale
@@ -16,4 +34,12 @@ module I18nAccessors
16
34
  "#{locale.to_s.downcase.sub("-", "_")}".freeze
17
35
  end
18
36
  end
37
+
38
+ class Configuration
39
+ attr_accessor :i18n_class
40
+
41
+ def initialize
42
+ @i18n_class ||= I18n
43
+ end
44
+ end
19
45
  end
@@ -34,13 +34,13 @@ If no locales are passed as an option to the initializer,
34
34
  locales.each do |locale|
35
35
  normalized_locale = I18nAccessors.normalize_locale(locale)
36
36
  define_method "#{attribute}_#{normalized_locale}" do |*args|
37
- I18n.with_locale(locale) { send(attribute, *args) }
37
+ I18nAccessors.i18n_class.with_locale(locale) { send(attribute, *args) }
38
38
  end
39
39
  define_method "#{attribute}_#{normalized_locale}?" do |*args|
40
- I18n.with_locale(locale) { send("#{attribute}?", *args) }
40
+ I18nAccessors.i18n_class.with_locale(locale) { send("#{attribute}?", *args) }
41
41
  end
42
42
  define_method "#{attribute}_#{normalized_locale}=" do |value, *args|
43
- I18n.with_locale(locale) { send("#{attribute}=", value, *args) }
43
+ I18nAccessors.i18n_class.with_locale(locale) { send("#{attribute}=", value, *args) }
44
44
  end
45
45
  end
46
46
  end
@@ -35,7 +35,7 @@ the method call.
35
35
  attribute = $1.to_sym
36
36
  locale, suffix = $2.split('_'.freeze)
37
37
  locale = "#{locale}-#{suffix.upcase}".freeze if suffix
38
- I18n.with_locale(locale) { public_send("#{attribute}#{$4}".freeze, *arguments) }
38
+ I18nAccessors.i18n_class.with_locale(locale.to_sym) { public_send("#{attribute}#{$4}".freeze, *arguments) }
39
39
  else
40
40
  super(method_name, *arguments, &block)
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module I18nAccessors
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg