Class: ThumbleMonks::ModelLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/thumblemonks/model_loader.rb

Overview

:nodoc

Direct Known Subclasses

AssociativeModelLoader, FromModelLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

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_toObject (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

#exceptObject (readonly)

Returns the value of attribute except.



5
6
7
# File 'lib/thumblemonks/model_loader.rb', line 5

def except
  @except
end

#onlyObject (readonly)

Returns the value of attribute only.



5
6
7
# File 'lib/thumblemonks/model_loader.rb', line 5

def only
  @only
end

#requiresObject (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

Returns:

  • (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

Returns:

  • (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

Raises:



24
25
26
# File 'lib/thumblemonks/model_loader.rb', line 24

def load_model(controller)
  raise NoModelLoaderFound
end