Class: Utopia::Controller::Action

Inherits:
Hash
  • Object
show all
Defined in:
lib/utopia/controller/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAction

Returns a new instance of Action.



24
25
26
27
28
29
30
# File 'lib/utopia/controller/action.rb', line 24

def initialize
  @path = nil
  @options = options
  @callback = nil
  
  super
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



32
33
34
# File 'lib/utopia/controller/action.rb', line 32

def callback
  @callback
end

#optionsObject

Returns the value of attribute options.



32
33
34
# File 'lib/utopia/controller/action.rb', line 32

def options
  @options
end

#pathObject

Returns the value of attribute path.



32
33
34
# File 'lib/utopia/controller/action.rb', line 32

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
# File 'lib/utopia/controller/action.rb', line 50

def == other
  super and @callback == other.callback and @options == other.options and @path == other.path
end

#arityObject



105
106
107
# File 'lib/utopia/controller/action.rb', line 105

def arity
  @callback ? @callback.arity : 0
end

#callback?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/utopia/controller/action.rb', line 34

def callback?
  @callback != nil
end

#define(path, **options, &callback) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/utopia/controller/action.rb', line 91

def define(path, **options, &callback)
  current = self
  
  path.reverse.each do |name|
    current = (current[name.to_sym] ||= Action.new)
  end
  
  current.path = path
  current.options = options
  current.callback = callback
  
  return current
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/utopia/controller/action.rb', line 42

def eql? other
  super and @callback.eql? other.callback and @options.eql? other.options and @path.eql? other.path 
end

#hashObject



46
47
48
# File 'lib/utopia/controller/action.rb', line 46

def hash
  [super, callback, options, path].hash
end

#indirect?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/utopia/controller/action.rb', line 38

def indirect?
  @options[:indirect]
end

#inspectObject



113
114
115
116
117
118
119
# File 'lib/utopia/controller/action.rb', line 113

def inspect
  if callback?
    "<action " + super + ":#{callback.source_location}(#{options})>"
  else
    "<action " + super + ">"
  end
end

#invoke!(controller, *arguments) ⇒ Object



109
110
111
# File 'lib/utopia/controller/action.rb', line 109

def invoke!(controller, *arguments)
  controller.instance_exec(*arguments, self, &@callback)
end

#select(relative_path) ⇒ Object

relative_path = 2014/mr-potato actions => => A



85
86
87
88
89
# File 'lib/utopia/controller/action.rb', line 85

def select(relative_path)
  [].tap do |actions|
    append(relative_path.reverse, 0, actions)
  end
end