Created
September 3, 2014 18:11
-
-
Save tfausak/c8dbc5c4890d1400116e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/active_interaction/base.rb b/lib/active_interaction/base.rb | |
index 64c70c3..9f5f61d 100644 | |
--- a/lib/active_interaction/base.rb | |
+++ b/lib/active_interaction/base.rb | |
@@ -168,7 +168,18 @@ module ActiveInteraction | |
attr_accessor filter.name | |
define_method("#{filter.name}?") { !public_send(filter.name).nil? } | |
- filter.default if filter.default? | |
+ initialize_default(filter) | |
+ end | |
+ | |
+ def initialize_default(filter) | |
+ return unless filter.default? | |
+ | |
+ default = filter.options.fetch(:default) | |
+ return filter.default unless default.is_a?(Proc) | |
+ | |
+ filter.options[:default] = nil | |
+ callback = -> { send("#{filter.name}=", instance_exec(&default)) } | |
+ set_callback(:type_check, :after, callback) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment