Class: IsPositionable::Interface

Inherits:
Base
  • Object
show all
Defined in:
lib/is_positionable/interface.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

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(options, controller_name)
  super({
    :column             => :position,
    :controller         => options[:controller] || controller_name,
    :model              => options[:controller] || controller_name,
    :action             => :positionable,
    :scope              => nil,
    :scope_object       => nil,
    :redirect_to        => :back,
    :param              => :move
  #  :set_default_scope  => true
  }.update(options))
end

Instance Method Details

#action_nameObject

Returns the action name of the :action attribute



58
59
60
# File 'lib/is_positionable/interface.rb', line 58

def action_name
  options[:action]
end

#buildObject



18
19
20
# File 'lib/is_positionable/interface.rb', line 18

def build
  self
end

#columnObject

Returns the column of the :column attribute



86
87
88
# File 'lib/is_positionable/interface.rb', line 86

def column
  options[:column]
end

#controllerObject

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_nameObject

Returns the controller name of the :controller attribute



76
77
78
# File 'lib/is_positionable/interface.rb', line 76

def controller_name
  options[: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

#modelObject

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(options[:model].singularize.camelize)
end

#model_association_nameObject

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
  options[:model].pluralize.underscore
end

#model_nameObject

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
  options[:model].singularize.camelize
end

#paramObject

Returns the param of the :param attribute



81
82
83
# File 'lib/is_positionable/interface.rb', line 81

def param
  options[:param]
end

#redirectObject

Returns the value of the :redirect_to attribute



34
35
36
# File 'lib/is_positionable/interface.rb', line 34

def redirect
  options[: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

#scopeObject

Returns the value of the :scope attribute



39
40
41
# File 'lib/is_positionable/interface.rb', line 39

def scope
  options[:scope]
end

#scope_objectObject



43
44
45
# File 'lib/is_positionable/interface.rb', line 43

def scope_object
  options[:scope_object]
end