Class: ThumbleMonks::ModelLoader
- Inherits:
-
Object
- Object
- ThumbleMonks::ModelLoader
- Defined in:
- lib/thumblemonks/model_loader.rb
Overview
:nodoc
Direct Known Subclasses
Instance Attribute Summary collapse
-
#assigns_to ⇒ Object
readonly
Returns the value of attribute assigns_to.
-
#except ⇒ Object
readonly
Returns the value of attribute except.
-
#only ⇒ Object
readonly
Returns the value of attribute only.
-
#requires ⇒ Object
readonly
Returns the value of attribute requires.
Instance Method Summary collapse
- #action_allowed?(action) ⇒ Boolean
- #action_required?(action) ⇒ Boolean
-
#initialize(name, opts = {}) ⇒ ModelLoader
constructor
A new instance of ModelLoader.
- #load_model(controller) ⇒ Object
Constructor Details
#initialize(name, opts = {}) ⇒ ModelLoader
Returns a new instance of ModelLoader.
7 8 9 10 11 12 13 |
# File 'lib/thumblemonks/model_loader.rb', line 7 def initialize(name, opts={}) config = {:require => false}.merge(opts) @assigns_to = "@#{name}".to_sym @requires = parse_required_actions(config[:require]) @except = stringify_array(config[:except]) @only = stringify_array(config[:only]) end |
Instance Attribute Details
#assigns_to ⇒ Object (readonly)
Returns the value of attribute assigns_to.
5 6 7 |
# File 'lib/thumblemonks/model_loader.rb', line 5 def assigns_to @assigns_to end |
#except ⇒ Object (readonly)
Returns the value of attribute except.
5 6 7 |
# File 'lib/thumblemonks/model_loader.rb', line 5 def except @except end |
#only ⇒ Object (readonly)
Returns the value of attribute only.
5 6 7 |
# File 'lib/thumblemonks/model_loader.rb', line 5 def only @only end |
#requires ⇒ Object (readonly)
Returns the value of attribute requires.
5 6 7 |
# File 'lib/thumblemonks/model_loader.rb', line 5 def requires @requires end |
Instance Method Details
#action_allowed?(action) ⇒ Boolean
15 16 17 18 |
# File 'lib/thumblemonks/model_loader.rb', line 15 def action_allowed?(action) return false if except.include?(action) only.empty? ? true : only.include?(action) end |
#action_required?(action) ⇒ Boolean
20 21 22 |
# File 'lib/thumblemonks/model_loader.rb', line 20 def action_required?(action) requires == true || requires.include?(action) end |
#load_model(controller) ⇒ Object
24 25 26 |
# File 'lib/thumblemonks/model_loader.rb', line 24 def load_model(controller) raise NoModelLoaderFound end |