modalh 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/h/active_record_extensions.rb +38 -15
- data/modalh.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
@@ -9,36 +9,57 @@ module H
|
|
9
9
|
module ActiveRecordExtensions
|
10
10
|
|
11
11
|
# Generic H field declarator
|
12
|
-
def _h(prefix, attr, *
|
12
|
+
def _h(prefix, attr, *args)
|
13
13
|
|
14
|
-
|
14
|
+
options = args.extract_options!
|
15
|
+
actual_attr = options.delete(:attribute) || attr
|
16
|
+
args << options unless options.empty?
|
17
|
+
|
18
|
+
instance_variable_set :"@#{attr}_h_options", args
|
15
19
|
|
16
20
|
class_eval do
|
17
21
|
|
18
|
-
validates_each
|
19
|
-
|
22
|
+
validates_each actual_attr do |record, attr_name, value|
|
23
|
+
if attr_name.to_s==actual_attr.to_s && record.send(:"#{attr}_h_invalid?")
|
24
|
+
record.errors.add attr_name.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if attr != actual_attr
|
29
|
+
define_method :"#{attr}" do
|
30
|
+
self.send :"#{actual_attr}"
|
31
|
+
end
|
32
|
+
define_method :"#{attr}=" do |v|
|
33
|
+
self.send :"#{actual_attr}=", v
|
34
|
+
end
|
20
35
|
end
|
21
36
|
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
37
|
+
if method_defined?(:"#{actual_attr}=")
|
38
|
+
define_method :"#{actual_attr}_with_#{prefix}_h=" do |v|
|
39
|
+
send :"#{actual_attr}_without_#{prefix}_h=", v
|
40
|
+
instance_variable_set "@#{attr}_h", nil
|
41
|
+
end
|
42
|
+
alias_method_chain :"#{actual_attr}=", :"#{prefix}_h"
|
43
|
+
else
|
44
|
+
define_method :"#{actual_attr}=" do |v|
|
45
|
+
write_attribute actual_attr, v
|
46
|
+
instance_variable_set "@#{attr}_h", nil
|
47
|
+
end
|
26
48
|
end
|
27
49
|
|
28
50
|
# attr_h
|
29
51
|
define_method :"#{attr}_h" do
|
30
|
-
|
31
|
-
|
32
|
-
instance_variable_set "@#{attr}_h",
|
33
|
-
|
34
|
-
|
52
|
+
unless (instance_variable_defined? "@#{attr}_h") && (h=instance_variable_get("@#{attr}_h")) && instance_variable_get("@#{attr}_h_locale")==I18n.locale
|
53
|
+
h = H.send(:"#{prefix}_to", send(attr), *self.class.instance_variable_get(:"@#{attr}_h_options"))
|
54
|
+
instance_variable_set "@#{attr}_h", h
|
55
|
+
instance_variable_set "@#{attr}_h_locale", I18n.locale
|
56
|
+
end
|
57
|
+
h
|
35
58
|
end
|
36
59
|
|
37
60
|
# attr_h=(txt)
|
38
61
|
define_method :"#{attr}_h=" do |txt|
|
39
|
-
instance_variable_set "@#{attr}_h", txt
|
40
62
|
instance_variable_set "@#{attr}_h_invalid", false
|
41
|
-
write_attribute attr, nil
|
42
63
|
unless txt.blank?
|
43
64
|
begin
|
44
65
|
v = H.send(:"#{prefix}_from", txt, *self.class.instance_variable_get(:"@#{attr}_h_options"))
|
@@ -48,6 +69,8 @@ module H
|
|
48
69
|
instance_variable_set "@#{attr}_h_invalid", true if v.nil?
|
49
70
|
end
|
50
71
|
send :"#{attr}=", v
|
72
|
+
instance_variable_set "@#{attr}_h", txt
|
73
|
+
instance_variable_set "@#{attr}_h_locale", I18n.locale
|
51
74
|
end
|
52
75
|
|
53
76
|
# attr_h? (returns true if it is valid and not blank)
|
data/modalh.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "modalh"
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Javier Goizueta"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-12"
|
13
13
|
s.description = "Rails plugin for localization & delocalization of data values"
|
14
14
|
s.email = "jgoizueta@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modalh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: units-system
|
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash:
|
165
|
+
hash: 2367165293756376042
|
166
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
167
|
none: false
|
168
168
|
requirements:
|