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 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
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 options[:writer] == true
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), :to => options[:to]
25
+ delegate *(readers + writers), options.dup
23
26
  end
24
27
 
25
- unless options[:errors] == false
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 options[:errors].to_s == "fit"}
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
@@ -1,3 +1,3 @@
1
1
  module DelegateAttributes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delegate_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: