Class: Flame::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/flame/router/route.rb

Overview

Class for Route in Router.routes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, action, method, ctrl_path, action_path) ⇒ Route

Returns a new instance of Route.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flame/router/route.rb', line 12

def initialize(controller, action, method, ctrl_path, action_path)
	@controller = controller
	@action = action
	@method = method.to_sym.upcase
	## Make path by controller method with parameners
	action_path = Flame::Path.new(action_path).adapt(controller, action)
	## Merge action path with controller path
	@path = Flame::Path.new(ctrl_path, action_path)
	Validators::RouteArgumentsValidator.new(
		@controller, action_path, @action
	).valid?
	freeze
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



10
11
12
# File 'lib/flame/router/route.rb', line 10

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



10
11
12
# File 'lib/flame/router/route.rb', line 10

def controller
  @controller
end

#methodObject (readonly)

Returns the value of attribute method.



10
11
12
# File 'lib/flame/router/route.rb', line 10

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/flame/router/route.rb', line 10

def path
  @path
end

Instance Method Details

#<=>(other) ⇒ Object

Compare by:

  1. path parts count (more is matter);

  2. args position (father is matter);

  3. HTTP-method (default).



53
54
55
56
57
# File 'lib/flame/router/route.rb', line 53

def <=>(other)
	path_result = other.path <=> path
	return path_result unless path_result.zero?
	method <=> other.method
end

#==(other) ⇒ Object

Method for Routes comparison



41
42
43
44
45
46
47
# File 'lib/flame/router/route.rb', line 41

def ==(other)
	%i[controller action method path].reduce(true) do |result, method|
		result && (
			public_send(method) == other.public_send(method)
		)
	end
end

#compare_attributes(attrs) ⇒ Object

Compare attributes for ‘Router.find_route`

Parameters:

  • attrs (Hash)

    Hash of attributes for comparing



33
34
35
36
37
38
# File 'lib/flame/router/route.rb', line 33

def compare_attributes(attrs)
	attrs.each do |name, value|
		next true if compare_attribute(name, value)
		break false
	end
end

#freezeObject



26
27
28
29
# File 'lib/flame/router/route.rb', line 26

def freeze
	@path.freeze
	super
end