lib/apidiesel/action.rb in apidiesel-0.9 vs lib/apidiesel/action.rb in apidiesel-0.10

- old
+ new

@@ -5,10 +5,12 @@ extend Dsl # accessors for class instance variables # (class-level variables, not shared with subclasses) class << self + include Handlers + attr_reader :url_args # Hash for storing validation closures. These closures are called with the request # parameters before the request is made and have the opportunity to check and modify them. def parameter_validations @@ -51,11 +53,13 @@ # # @param [String] value def url(value = nil, **args) return @url unless value || args.any? - if value + if value && value.is_a?(Proc) + @url = value + elsif value @url = URI.parse(value) else @url_args = args end end @@ -122,13 +126,24 @@ def endpoint self.class.endpoint end + def base_url + if self.class.url.nil? || self.class.url.is_a?(Proc) + @api.class.url.dup + else + self.class.url.dup + end + end + def url - url = self.class.url || @api.class.url + if self.class.url.is_a?(Proc) + url = self.class.url - if self.class.url_args + elsif self.class.url_args + url = base_url + self.class.url_args.each do |key, value| url.send("#{key}=", value) end end