hstore_translate 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.
- data/Gemfile.lock +7 -7
- data/README.md +1 -1
- data/lib/hstore_translate/translates.rb +22 -7
- data/lib/hstore_translate/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hstore_translate (0.0.
|
5
|
-
activerecord
|
4
|
+
hstore_translate (0.0.4)
|
5
|
+
activerecord (>= 3.1.0)
|
6
6
|
activerecord-postgres-hstore (~> 0.4.0)
|
7
7
|
|
8
8
|
GEM
|
@@ -45,16 +45,16 @@ GEM
|
|
45
45
|
hike (1.2.1)
|
46
46
|
i18n (0.6.1)
|
47
47
|
journey (1.0.4)
|
48
|
-
json (1.7.
|
48
|
+
json (1.7.7)
|
49
49
|
mail (2.4.4)
|
50
50
|
i18n (>= 0.4.0)
|
51
51
|
mime-types (~> 1.16)
|
52
52
|
treetop (~> 1.4.8)
|
53
|
-
mime-types (1.
|
54
|
-
multi_json (1.
|
53
|
+
mime-types (1.21)
|
54
|
+
multi_json (1.6.1)
|
55
55
|
pg (0.14.1)
|
56
56
|
polyglot (0.3.3)
|
57
|
-
rack (1.4.
|
57
|
+
rack (1.4.5)
|
58
58
|
rack-cache (1.2)
|
59
59
|
rack (>= 0.4)
|
60
60
|
rack-ssl (1.3.2)
|
@@ -77,7 +77,7 @@ GEM
|
|
77
77
|
rdoc (~> 3.4)
|
78
78
|
thor (>= 0.14.6, < 2.0)
|
79
79
|
rake (10.0.3)
|
80
|
-
rdoc (3.12)
|
80
|
+
rdoc (3.12.2)
|
81
81
|
json (~> 1.4)
|
82
82
|
sprockets (2.2.2)
|
83
83
|
hike (~> 1.2)
|
data/README.md
CHANGED
@@ -47,7 +47,7 @@ I18n.locale = :he
|
|
47
47
|
post.title # => אתר זה טוב
|
48
48
|
```
|
49
49
|
|
50
|
-
You also have locale-specific convenience methods:
|
50
|
+
You also have locale-specific convenience methods from [easy_globalize3_accessors](https://github.com/paneq/easy_globalize3_accessors):
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
I18n.locale = :en
|
@@ -20,6 +20,7 @@ module HstoreTranslate
|
|
20
20
|
RUBY
|
21
21
|
end
|
22
22
|
|
23
|
+
alias_method_chain :respond_to?, :translates
|
23
24
|
alias_method_chain :method_missing, :translates
|
24
25
|
end
|
25
26
|
|
@@ -45,20 +46,34 @@ module HstoreTranslate
|
|
45
46
|
value
|
46
47
|
end
|
47
48
|
|
49
|
+
def respond_to_with_translates?(symbol, include_all = false)
|
50
|
+
return true if parse_translated_attribute_accessor(symbol)
|
51
|
+
respond_to_without_translates?(symbol, include_all)
|
52
|
+
end
|
53
|
+
|
48
54
|
def method_missing_with_translates(method_name, *args)
|
49
|
-
|
50
|
-
method_name =~ /\A([a-z_]+)_([a-z]{2})(=?)\z/ &&
|
51
|
-
(attr_name = $1.to_sym) && translated_attrs.include?(attr_name)
|
55
|
+
translated_attr_name, locale, assigning = parse_translated_attribute_accessor(method_name)
|
52
56
|
|
53
|
-
|
54
|
-
assigning = $3.present?
|
57
|
+
return method_missing_without_translates(method_name, *args) unless translated_attr_name
|
55
58
|
|
56
59
|
if assigning
|
57
|
-
write_hstore_translation(
|
60
|
+
write_hstore_translation(translated_attr_name, args.first, locale)
|
58
61
|
else
|
59
|
-
read_hstore_translation(
|
62
|
+
read_hstore_translation(translated_attr_name, locale)
|
60
63
|
end
|
61
64
|
end
|
65
|
+
|
66
|
+
def parse_translated_attribute_accessor(method_name)
|
67
|
+
return unless method_name =~ /\A([a-z_]+)_([a-z]{2})(=?)\z/
|
68
|
+
|
69
|
+
translated_attr_name = $1.to_sym
|
70
|
+
return unless translated_attrs.include?(translated_attr_name)
|
71
|
+
|
72
|
+
locale = $2.to_sym
|
73
|
+
assigning = $3.present?
|
74
|
+
|
75
|
+
[translated_attr_name, locale, assigning]
|
76
|
+
end
|
62
77
|
end
|
63
78
|
end
|
64
79
|
end
|