Class: MuchRails::Action::BaseRouter::URLSet
- Inherits:
-
Object
- Object
- MuchRails::Action::BaseRouter::URLSet
- Defined in:
- lib/much-rails/action/base_router.rb
Instance Method Summary collapse
- #add(name, path) ⇒ Object
- #empty? ⇒ Boolean
- #fetch(name, default_value = nil, &block) ⇒ Object
-
#initialize(router) ⇒ URLSet
constructor
A new instance of URLSet.
- #path_for(name, **kargs) ⇒ Object
- #url_for(name, **kargs) ⇒ Object
- #urls ⇒ Object
Constructor Details
#initialize(router) ⇒ URLSet
Returns a new instance of URLSet.
315 316 317 318 |
# File 'lib/much-rails/action/base_router.rb', line 315 def initialize(router) @set = {} @router = router end |
Instance Method Details
#add(name, path) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/much-rails/action/base_router.rb', line 328 def add(name, path) url = @router.url_class.new(@router, path, name.to_sym) key = url.name unless @set[key].nil? raise( ArgumentError, "There is already a URL named `#{name.to_sym.inspect}`.", ) end @set[key] = url end |
#empty? ⇒ Boolean
320 321 322 |
# File 'lib/much-rails/action/base_router.rb', line 320 def empty? @set.empty? end |
#fetch(name, default_value = nil, &block) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/much-rails/action/base_router.rb', line 341 def fetch(name, default_value = nil, &block) key = @router.url_class.url_name(@router, name.to_sym) if default_value @set.fetch(key, default_value) else @set.fetch( key, &( block || proc{ raise( ArgumentError, "There is no URL named `#{name.to_sym.inspect}`.", ) } ) ) end end |
#path_for(name, **kargs) ⇒ Object
361 362 363 |
# File 'lib/much-rails/action/base_router.rb', line 361 def path_for(name, **kargs) fetch(name).path_for(**kargs) end |
#url_for(name, **kargs) ⇒ Object
365 366 367 |
# File 'lib/much-rails/action/base_router.rb', line 365 def url_for(name, **kargs) fetch(name).url_for(**kargs) end |
#urls ⇒ Object
324 325 326 |
# File 'lib/much-rails/action/base_router.rb', line 324 def urls @set.values end |