Class: Kuebiko::Url
- Inherits:
-
Object
- Object
- Kuebiko::Url
- Defined in:
- lib/kuebiko/url.rb,
lib/kuebiko/url/material.rb,
lib/kuebiko/url/components.rb
Constant Summary collapse
- @@components =
{}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*_, **options) ⇒ Url
constructor
A new instance of Url.
Constructor Details
#initialize(*_, **options) ⇒ Url
Returns a new instance of Url.
34 35 36 |
# File 'lib/kuebiko/url.rb', line 34 def initialize(*_, **) @_options = end |
Class Method Details
.default_components(options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/kuebiko/url/components.rb', line 10 def default_components( = {}) .each do |comp, value| raise ArgumentError, "unknown components #{comp.inspect}" unless COMPONENTS.include?(comp) instance_eval "#{comp}(value)" end end |
.material(*names) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/kuebiko/url/material.rb', line 4 def material(*names) class_eval <<-DEF_INIT, __FILE__, __LINE__ + 1 def initialize(*materials, **options) #{names.map{|n| "@_#{n}"}.join(", ")}, _dust = materials @_options = options end #{names.map{|n| "def #{n}; @_#{n}; end"}.join("\n")} private #{names.map{|n| ":#{n}"}.join(", ")} DEF_INIT end |
.method_added(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kuebiko/url.rb', line 7 def self.method_added(name) return unless public_method_defined?(name) return if /_(path|url)\z/ === name class_eval <<-DEF_URL_METHOD, __FILE__, __LINE__ + 1 class << self def #{name}_path(*args, **options) new(*args, **options).#{name}_path end def #{name}_url(*args, **options) new(*args, **options).#{name}_url end end def #{name}_path(options = {}) "/" + #{name}.build end def #{name}_url(options = {}) url = my_scheme.to_s + "://" + my_host.to_s url << (":" + my_port.to_s) if my_port url + "/" + #{name}.build end DEF_URL_METHOD end |