Class: IsPositionable::Interface
- Defined in:
- lib/is_positionable/interface.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#action_name ⇒ Object
Returns the action name of the :action attribute.
- #build ⇒ Object
-
#column ⇒ Object
Returns the column of the :column attribute.
-
#controller ⇒ Object
Returns the controller Class which can be invoked using class methods.
-
#controller_name ⇒ Object
Returns the controller name of the :controller attribute.
-
#find(id) ⇒ Object
Finds a single record by id It will determine whether to use a plain find or whether to use a find through an association.
-
#initialize(options, controller_name) ⇒ Interface
constructor
A new instance of Interface.
-
#model ⇒ Object
Returns the model Class which can be invoked using class methods.
-
#model_association_name ⇒ Object
Returns the model name in the form of an association This is the model name, pluralize’d and underscore’d.
-
#model_name ⇒ Object
Returns the model name of the :model attribute The value will be singularize’d and camelize’d to return the exact name as it is written inside a Ruby file.
-
#param ⇒ Object
Returns the param of the :param attribute.
-
#redirect ⇒ Object
Returns the value of the :redirect_to attribute.
-
#require_gem(gem, ignore_error = true) ⇒ Object
Require additional gems When the “ignore_error” argument is set to “true” (default) an error will not be raised if the gem cannot be found.
-
#scope ⇒ Object
Returns the value of the :scope attribute.
- #scope_object ⇒ Object
Constructor Details
#initialize(options, controller_name) ⇒ Interface
Returns a new instance of Interface.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/is_positionable/interface.rb', line 4 def initialize(, controller_name) super({ :column => :position, :controller => [:controller] || controller_name, :model => [:controller] || controller_name, :action => :positionable, :scope => nil, :scope_object => nil, :redirect_to => :back, :param => :move # :set_default_scope => true }.update()) end |
Instance Method Details
#action_name ⇒ Object
Returns the action name of the :action attribute
58 59 60 |
# File 'lib/is_positionable/interface.rb', line 58 def action_name [:action] end |
#build ⇒ Object
18 19 20 |
# File 'lib/is_positionable/interface.rb', line 18 def build self end |
#column ⇒ Object
Returns the column of the :column attribute
86 87 88 |
# File 'lib/is_positionable/interface.rb', line 86 def column [:column] end |
#controller ⇒ Object
Returns the controller Class which can be invoked using class methods
53 54 55 |
# File 'lib/is_positionable/interface.rb', line 53 def controller Kernel.const_get("#{controller_name.camelize.pluralize}Controller") end |
#controller_name ⇒ Object
Returns the controller name of the :controller attribute
76 77 78 |
# File 'lib/is_positionable/interface.rb', line 76 def controller_name [:controller] end |
#find(id) ⇒ Object
Finds a single record by id It will determine whether to use a plain find or whether to use a find through an association
25 26 27 28 29 30 31 |
# File 'lib/is_positionable/interface.rb', line 25 def find(id) if scope_object.nil? model.find(id) else scope_object.send(model_association_name).find(id) end end |
#model ⇒ Object
Returns the model Class which can be invoked using class methods
48 49 50 |
# File 'lib/is_positionable/interface.rb', line 48 def model Kernel.const_get([:model].singularize.camelize) end |
#model_association_name ⇒ Object
Returns the model name in the form of an association This is the model name, pluralize’d and underscore’d
71 72 73 |
# File 'lib/is_positionable/interface.rb', line 71 def model_association_name [:model].pluralize.underscore end |
#model_name ⇒ Object
Returns the model name of the :model attribute The value will be singularize’d and camelize’d to return the exact name as it is written inside a Ruby file
65 66 67 |
# File 'lib/is_positionable/interface.rb', line 65 def model_name [:model].singularize.camelize end |
#param ⇒ Object
Returns the param of the :param attribute
81 82 83 |
# File 'lib/is_positionable/interface.rb', line 81 def param [:param] end |
#redirect ⇒ Object
Returns the value of the :redirect_to attribute
34 35 36 |
# File 'lib/is_positionable/interface.rb', line 34 def redirect [:redirect_to] end |
#require_gem(gem, ignore_error = true) ⇒ Object
Require additional gems When the “ignore_error” argument is set to “true” (default) an error will not be raised if the gem cannot be found
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/is_positionable/interface.rb', line 99 def require_gem(gem, ignore_error = true) if ignore_error.eql?(true) begin require "#{gem}" rescue MissingSourceFile end else require "#{gem}" end end |
#scope ⇒ Object
Returns the value of the :scope attribute
39 40 41 |
# File 'lib/is_positionable/interface.rb', line 39 def scope [:scope] end |
#scope_object ⇒ Object
43 44 45 |
# File 'lib/is_positionable/interface.rb', line 43 def scope_object [:scope_object] end |