Class: Restful::UrlFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/restful/serializer.rb

Overview

Enables local generation of named_routes with preset arguments:

  • :api_prefix

  • :default_url_options

Used by Serializer and Association to customize urls for their WebService.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ UrlFactory

Returns a new instance of UrlFactory.



15
16
17
18
# File 'lib/restful/serializer.rb', line 15

def initialize(options)
  self.api_prefix = options[:api_prefix]
  self.default_url_options = options[:default_url_options] || {}
end

Instance Attribute Details

#api_prefixObject

Returns the value of attribute api_prefix.



13
14
15
# File 'lib/restful/serializer.rb', line 13

def api_prefix
  @api_prefix
end

#default_url_optionsObject

Returns the value of attribute default_url_options.



13
14
15
# File 'lib/restful/serializer.rb', line 13

def default_url_options
  @default_url_options
end

Instance Method Details

#create(options) ⇒ Object

Url.for but with UrlFactory’s options slipped in.



21
22
23
24
# File 'lib/restful/serializer.rb', line 21

def create(options)
  create_options = {:api_prefix => api_prefix}.merge(options).deep_merge(:named_route_options => default_url_options)
  Url.for(create_options)
end