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(*_, **) = 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 initialize(*materials, **options)\n \#{names.map{|n| \"@_\#{n}\"}.join(\", \")}, _dust = materials\n @_options = options\n end\n\n \#{names.map{|n| \"def \#{n}; @_\#{n}; end\"}.join(\"\\n\")}\n private \#{names.map{|n| \":\#{n}\"}.join(\", \")}\n DEF_INIT\nend\n", __FILE__, __LINE__ + 1 |
.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 " class << self\n def \#{name}_path(*args, **options)\n new(*args, **options).\#{name}_path\n end\n\n def \#{name}_url(*args, **options)\n new(*args, **options).\#{name}_url\n end\n end\n\n def \#{name}_path(options = {})\n \"/\" + \#{name}.build\n end\n\n def \#{name}_url(options = {})\n url = my_scheme.to_s + \"://\" + my_host.to_s\n url << (\":\" + my_port.to_s) if my_port\n url + \"/\" + \#{name}.build\n end\n DEF_URL_METHOD\nend\n", __FILE__, __LINE__ + 1 |