Class: Plutonium::Action::RouteOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/action/route_options.rb

Overview

RouteOptions class for handling routing options in the Plutonium framework.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*url_args, method: :get, url_resolver: :resource_url_for, **url_options) ⇒ RouteOptions

Initialize a new RouteOptions instance.

Parameters:

  • The positional arguments for URL generation.

  • (defaults to: :get)

    The HTTP method for the route (default: :get).

  • (defaults to: :resource_url_for)

    The method to use for resolving URLs (default: :resource_url_for).

  • URL options for the route.



20
21
22
23
24
25
26
# File 'lib/plutonium/action/route_options.rb', line 20

def initialize(*url_args, method: :get, url_resolver: :resource_url_for, **url_options)
  @method = method
  @url_resolver = url_resolver
  @url_args = url_args
  @url_options = url_options.freeze
  freeze
end

Instance Attribute Details

#methodSymbol (readonly)

The HTTP method for the route.

Returns:

  • the current value of method



11
12
13
# File 'lib/plutonium/action/route_options.rb', line 11

def method
  @method
end

#url_argsArray (readonly)

The positional arguments for URL generation.

Returns:

  • the current value of url_args



11
12
13
# File 'lib/plutonium/action/route_options.rb', line 11

def url_args
  @url_args
end

#url_optionsHash (readonly)

URL options for the route.

Returns:

  • the current value of url_options



11
12
13
# File 'lib/plutonium/action/route_options.rb', line 11

def url_options
  @url_options
end

#url_resolverSymbol (readonly)

The method to use for resolving URLs.

Returns:

  • the current value of url_resolver



11
12
13
# File 'lib/plutonium/action/route_options.rb', line 11

def url_resolver
  @url_resolver
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/plutonium/action/route_options.rb', line 48

def ==(other)
  self.class == other.class &&
    method == other.method &&
    url_resolver == other.url_resolver &&
    url_args == other.url_args &&
    url_options == other.url_options
end

#eql?(other) ⇒ Boolean

Returns:



56
57
58
# File 'lib/plutonium/action/route_options.rb', line 56

def eql?(other)
  self == other
end

#hashObject



60
61
62
# File 'lib/plutonium/action/route_options.rb', line 60

def hash
  [self.class, method, url_resolver, url_args, url_options].hash
end

#merge(other) ⇒ RouteOptions

Merge this RouteOptions with another RouteOptions instance.

Parameters:

  • The other RouteOptions instance to merge with.

Returns:

  • A new RouteOptions instance with merged values.



39
40
41
42
43
44
45
46
# File 'lib/plutonium/action/route_options.rb', line 39

def merge(other)
  self.class.new(
    *(@url_args | other.url_args),
    method: other.method || @method,
    url_resolver: other.url_resolver || @url_resolver,
    **@url_options.merge(other.url_options)
  )
end

#to_url_argsArray

Convert the RouteOptions to arguments suitable for URL helpers.

Returns:

  • The arguments for URL generation.



31
32
33
# File 'lib/plutonium/action/route_options.rb', line 31

def to_url_args
  @url_args + [@url_options]
end