delegate_attributes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/delegate_attributes.gemspec +0 -0
- data/lib/delegate_attributes/engine.rb +0 -0
- data/lib/delegate_attributes/models/active_record_extension.rb +8 -5
- data/lib/delegate_attributes/models/fake_errors.rb +0 -0
- data/lib/delegate_attributes/railtie.rb +0 -0
- data/lib/delegate_attributes/version.rb +1 -1
- data/lib/delegate_attributes.rb +0 -0
- metadata +1 -1
data/.gitignore
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/delegate_attributes.gemspec
CHANGED
File without changes
|
File without changes
|
@@ -11,22 +11,25 @@ module DelegateAttributes
|
|
11
11
|
|
12
12
|
def delegate_attributes(*args)
|
13
13
|
options = args.extract_options!
|
14
|
+
errors_option = options.delete(:errors)
|
15
|
+
writer_option = options.delete(:writer)
|
16
|
+
|
14
17
|
writer_regexp = /=\z/
|
15
18
|
readers = args.select {|a| a.to_s !=~ writer_regexp}
|
16
19
|
writers = args.select {|a| a.to_s =~ writer_regexp}
|
17
|
-
if
|
20
|
+
if writer_option == true
|
18
21
|
writers += readers.map {|a| "#{a}="}
|
19
22
|
end
|
20
|
-
|
23
|
+
|
21
24
|
class_eval do
|
22
|
-
delegate *(readers + writers),
|
25
|
+
delegate *(readers + writers), options.dup
|
23
26
|
end
|
24
27
|
|
25
|
-
unless
|
28
|
+
unless errors_option == false
|
26
29
|
class_eval <<-EOV
|
27
30
|
validate do
|
28
31
|
object = #{options[:to]}
|
29
|
-
#{"object.instance_variable_set(:@errors, DelegateAttributes::FakeErrors.new(object))" if
|
32
|
+
#{"object.instance_variable_set(:@errors, DelegateAttributes::FakeErrors.new(object))" if errors_option.to_s == "fit"}
|
30
33
|
if !object.valid?
|
31
34
|
object.errors.messages.each do |attribute, suberrors|
|
32
35
|
if attribute.to_s.in? %w{#{readers.join(" ")}}
|
File without changes
|
File without changes
|
data/lib/delegate_attributes.rb
CHANGED
File without changes
|