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

#initialize(options = {}, &block) ⇒ Action

Returns a new instance of Action.



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

def initialize(options = {}, &block)
	@options = options
	@callback = block
	
	super()
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



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

def callback
  @callback
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(controller, *arguments) ⇒ Object



103
104
105
# File 'lib/utopia/controller/action.rb', line 103

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

#callback?Boolean

Returns:

  • (Boolean)


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

def callback?
	@callback != nil
end

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



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

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)


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

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

#hashObject



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

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

#indirect?Boolean

Returns:

  • (Boolean)


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

def indirect?
	@options[:indirect]
end

#inspectObject



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

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

#select(relative_path) ⇒ Object

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



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

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