Class: Utopia::Middleware::Controller::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#symbolize_keys

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



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

def callback
  @callback
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
# File 'lib/utopia/middleware/controller/action.rb', line 44

def == other
	super and (self.callback == other.callback) and (self.options == other.options)
end

#callback?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/utopia/middleware/controller/action.rb', line 28

def callback?
	@callback != nil
end

#define(path, options = {}, &callback) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/utopia/middleware/controller/action.rb', line 89

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/utopia/middleware/controller/action.rb', line 36

def eql? other
	super and self.callback.eql? other.callback and self.options.eql? other.options
end

#hashObject



40
41
42
# File 'lib/utopia/middleware/controller/action.rb', line 40

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

#indirect?Boolean

Returns:

  • (Boolean)


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

def indirect?
	@options[:indirect]
end

#inspectObject



111
112
113
114
115
116
117
# File 'lib/utopia/middleware/controller/action.rb', line 111

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

#invoke!(controller, *arguments) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/utopia/middleware/controller/action.rb', line 102

def invoke!(controller, *arguments)
	if @options[:unbound]
		# This is the old code path for explicit methods.
		controller.instance_exec(controller, *arguments, &@callback)
	else
		controller.instance_exec(*arguments, &@callback)
	end
end

#select(relative_path) ⇒ Object

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



79
80
81
82
83
84
85
86
87
# File 'lib/utopia/middleware/controller/action.rb', line 79

def select(relative_path)
	actions = []
	
	append(relative_path.reverse, 0, actions)
	
	# puts "select(#{relative_path}, #{self.inspect}) => #{actions.inspect}"
	
	return actions
end