Module: ActsAsMultipartForm::MultipartFormInModel::InstanceMethods
- Defined in:
- lib/acts_as_multipart_form/multipart_form_in_model.rb
Instance Method Summary collapse
-
#method_missing(sym, *args) ⇒ Object
Overrides method missing to return true if the method is of the form multipart_form_name_multipart_controller_action.
-
#multipart_form_controller_action?(sym) ⇒ Boolean
Determines if the symbol corresponds to a multipart form action.
-
#multipart_form_method?(sym) ⇒ Boolean
determines whether the given method should be handled by the multipart form method handler based on whether it starts with the form name followed by an underscore.
-
#reset_multipart_form_controller_action ⇒ Object
Sets the controller action to nil When we are not performing a save (or other action from a controller), the controller action should not be set.
-
#respond_to?(sym, *args) ⇒ Boolean
Overrides respond to to return true if the method is of the form multipart_form_name_multipart_controller_action.
-
#using_multipart_forms? ⇒ Boolean
Determines whether multipart form controller is in use.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
Overrides method missing to return true if the method is of the form multipart_form_name_multipart_controller_action
If those conditions are not satisfied, called super
58 59 60 61 62 63 64 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 58 def method_missing(sym, *args) if multipart_form_method?(sym) return multipart_form_controller_action?(sym) else super end end |
Instance Method Details
#multipart_form_controller_action?(sym) ⇒ Boolean
Determines if the symbol corresponds to a multipart form action
97 98 99 100 101 102 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 97 def multipart_form_controller_action?(sym) if using_multipart_forms? return self.multipart_forms.select {|form| form.to_s + "_" + self.multipart_form_controller_action + "?" == sym.to_s}.length > 0 end return false end |
#multipart_form_method?(sym) ⇒ Boolean
determines whether the given method should be handled by the multipart form method handler based on whether it starts with the form name followed by an underscore
87 88 89 90 91 92 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 87 def multipart_form_method?(sym) if self.multipart_forms return self.multipart_forms.select {|form| sym.to_s =~ /^#{form}_/}.length > 0 end return false end |
#reset_multipart_form_controller_action ⇒ Object
Sets the controller action to nil When we are not performing a save (or other action from a controller), the controller action should not be set
40 41 42 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 40 def reset_multipart_form_controller_action self.multipart_form_controller_action = nil end |
#respond_to?(sym, *args) ⇒ Boolean
Overrides respond to to return true if the method is of the form multipart_form_name_multipart_controller_action
If those conditions are not satisfied, called super
74 75 76 77 78 79 80 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 74 def respond_to?(sym, *args) if multipart_form_method?(sym) return multipart_form_controller_action?(sym) else super end end |
#using_multipart_forms? ⇒ Boolean
Determines whether multipart form controller is in use
46 47 48 |
# File 'lib/acts_as_multipart_form/multipart_form_in_model.rb', line 46 def using_multipart_forms? return(!self.multipart_forms.nil? && !self.multipart_form_controller_action.nil?) end |