Class: Utopia::Controller::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



24
25
26
# File 'lib/utopia/controller/action.rb', line 24

def callback
  @callback
end

#optionsObject

Returns the value of attribute options.



24
25
26
# File 'lib/utopia/controller/action.rb', line 24

def options
  @options
end

#pathObject

Returns the value of attribute path.



24
25
26
# File 'lib/utopia/controller/action.rb', line 24

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



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

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

#arityObject



97
98
99
# File 'lib/utopia/controller/action.rb', line 97

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

#callback?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/utopia/controller/action.rb', line 26

def callback?
	@callback != nil
end

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



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/utopia/controller/action.rb', line 83

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)


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

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

#hashObject



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

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

#indirect?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/utopia/controller/action.rb', line 30

def indirect?
	@options[:indirect]
end

#inspectObject



105
106
107
108
109
110
111
# File 'lib/utopia/controller/action.rb', line 105

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

#invoke!(controller, *arguments) ⇒ Object



101
102
103
# File 'lib/utopia/controller/action.rb', line 101

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

#select(relative_path) ⇒ Object

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



77
78
79
80
81
# File 'lib/utopia/controller/action.rb', line 77

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