Class: MuchRails::Action::BaseRouter::BaseURL

Inherits:
Object
  • Object
show all
Defined in:
lib/much-rails/action/base_router.rb

Direct Known Subclasses

Router::URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router, url_path, url_name = nil) ⇒ BaseURL

Returns a new instance of BaseURL.



393
394
395
396
397
# File 'lib/much-rails/action/base_router.rb', line 393

def initialize(router, url_path, url_name = nil)
  @router   = router
  @url_path = url_path.to_s
  @url_name = url_name&.to_sym
end

Instance Attribute Details

#routerObject (readonly)

Returns the value of attribute router.



391
392
393
# File 'lib/much-rails/action/base_router.rb', line 391

def router
  @router
end

#url_nameObject (readonly)

Returns the value of attribute url_name.



391
392
393
# File 'lib/much-rails/action/base_router.rb', line 391

def url_name
  @url_name
end

#url_pathObject (readonly)

Returns the value of attribute url_path.



391
392
393
# File 'lib/much-rails/action/base_router.rb', line 391

def url_path
  @url_path
end

Class Method Details

.for(router, url_or_path) ⇒ Object



385
386
387
388
389
# File 'lib/much-rails/action/base_router.rb', line 385

def self.for(router, url_or_path)
  return url_or_path if url_or_path.is_a?(self)

  new(router, url_or_path)
end

.url_name(router, name) ⇒ Object



371
372
373
374
375
376
# File 'lib/much-rails/action/base_router.rb', line 371

def self.url_name(router, name)
  return unless name
  return name unless router&.name

  "#{router.name}_#{name}".to_sym
end

.url_path(router, path) ⇒ Object



378
379
380
381
382
383
# File 'lib/much-rails/action/base_router.rb', line 378

def self.url_path(router, path)
  return unless path
  return path unless router&.base_url

  File.join(router.base_url, path)
end

Instance Method Details

#==(other) ⇒ Object



415
416
417
418
419
420
421
# File 'lib/much-rails/action/base_router.rb', line 415

def ==(other)
  return super unless other.is_a?(self.class)

  @router   == other.router &&
  @url_path == other.url_path &&
  @url_name == other.url_name
end

#nameObject



399
400
401
# File 'lib/much-rails/action/base_router.rb', line 399

def name
  self.class.url_name(@router, @url_name)
end

#pathObject



403
404
405
# File 'lib/much-rails/action/base_router.rb', line 403

def path
  self.class.url_path(@router, @url_path)
end

#path_for(**kargs) ⇒ Object

Raises:

  • (NotImplementedError)


407
408
409
# File 'lib/much-rails/action/base_router.rb', line 407

def path_for(**kargs)
  raise NotImplementedError
end

#url_for(**kargs) ⇒ Object

Raises:

  • (NotImplementedError)


411
412
413
# File 'lib/much-rails/action/base_router.rb', line 411

def url_for(**kargs)
  raise NotImplementedError
end