lib/sinatra/subdomain.rb in sinatra-subdomain-0.2.0 vs lib/sinatra/subdomain.rb in sinatra-subdomain-0.2.1
- old
+ new
@@ -17,11 +17,11 @@
parts.empty? ? nil : parts.join(".")
end
end
- def subdomain(expected_subdomain = true, &block)
+ def subdomain(expected_subdomain = true)
::Sinatra::Subdomain.tap do |mod|
mod.app = self
mod.subdomain = expected_subdomain
end
@@ -35,27 +35,37 @@
def self.ip_address?(host)
host =~ Resolv::IPv4::Regex || host =~ Resolv::IPv6::Regex
end
- def self.route_added(verb, path, block)
+ def self.route_added(verb, _path, _block)
return unless subdomain && app
routes = app.instance_variable_get("@routes")
last_route = routes[verb].last
expected = subdomain
condition = app.instance_eval do
generate_method :subdomain do
if expected == true
- subdomain != nil
+ !subdomain.nil?
else
subdomain.to_s == expected.to_s
end
end
end
- last_route[2] << condition
+ add_condition(last_route, condition)
+ end
+
+ if Gem::Requirement.create(["~>2.0"]).satisfied_by?(Gem::Version.create(Sinatra::VERSION))
+ def self.add_condition(last_route, condition)
+ last_route[1] << condition
+ end
+ else
+ def self.add_condition(last_route, condition)
+ last_route[2] << condition
+ end
end
def self.registered(app)
app.helpers Sinatra::Subdomain::Helpers
app.set :tld_size, 1