Class: ThumbleMonks::AssociativeModelLoader
- Inherits:
-
ModelLoader
- Object
- ModelLoader
- ThumbleMonks::AssociativeModelLoader
- Defined in:
- lib/thumblemonks/model_loader.rb
Overview
ModelLoader
Direct Known Subclasses
Instance Attribute Summary collapse
-
#foreign_key ⇒ Object
readonly
:nodoc.
-
#load_through ⇒ Object
readonly
:nodoc.
-
#parameter_key ⇒ Object
readonly
:nodoc.
Attributes inherited from ModelLoader
#assigns_to, #except, #only, #requires
Instance Method Summary collapse
-
#initialize(name, opts = {}) ⇒ AssociativeModelLoader
constructor
A new instance of AssociativeModelLoader.
- #load_model(controller) ⇒ Object
Methods inherited from ModelLoader
#action_allowed?, #action_required?
Constructor Details
#initialize(name, opts = {}) ⇒ AssociativeModelLoader
Returns a new instance of AssociativeModelLoader.
44 45 46 47 48 49 50 |
# File 'lib/thumblemonks/model_loader.rb', line 44 def initialize(name, opts={}) super config = {:parameter_key => :id, :foreign_key => :id, :class => name}.merge(opts) @load_through = config[:class].to_s.classify.constantize @parameter_key = config[:parameter_key].to_s @foreign_key = config[:foreign_key].to_s end |
Instance Attribute Details
#foreign_key ⇒ Object (readonly)
:nodoc
42 43 44 |
# File 'lib/thumblemonks/model_loader.rb', line 42 def foreign_key @foreign_key end |
#load_through ⇒ Object (readonly)
:nodoc
42 43 44 |
# File 'lib/thumblemonks/model_loader.rb', line 42 def load_through @load_through end |
#parameter_key ⇒ Object (readonly)
:nodoc
42 43 44 |
# File 'lib/thumblemonks/model_loader.rb', line 42 def parameter_key @parameter_key end |
Instance Method Details
#load_model(controller) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/thumblemonks/model_loader.rb', line 52 def load_model(controller) begin lookup = parameter_value(controller) source(controller).send("find_by_#{foreign_key}", lookup) unless lookup.blank? rescue ActiveRecord::StatementInvalid nil end end |