Class: RemoteResource::UrlNamingDetermination
- Inherits:
-
Object
- Object
- RemoteResource::UrlNamingDetermination
- Defined in:
- lib/remote_resource/url_naming_determination.rb
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
readonly
Returns the value of attribute connection_options.
-
#resource_klass ⇒ Object
readonly
Returns the value of attribute resource_klass.
Instance Method Summary collapse
- #base_url(id = nil, check_collection_options: false) ⇒ Object
- #collection_prefix(check_collection_options) ⇒ Object
-
#initialize(resource_klass, connection_options = {}) ⇒ UrlNamingDetermination
constructor
A new instance of UrlNamingDetermination.
- #relative_name ⇒ Object
- #url_safe_relative_name ⇒ Object
Constructor Details
#initialize(resource_klass, connection_options = {}) ⇒ UrlNamingDetermination
Returns a new instance of UrlNamingDetermination.
6 7 8 9 |
# File 'lib/remote_resource/url_naming_determination.rb', line 6 def initialize(resource_klass, = {}) @resource_klass = resource_klass @connection_options = end |
Instance Attribute Details
#connection_options ⇒ Object (readonly)
Returns the value of attribute connection_options.
4 5 6 |
# File 'lib/remote_resource/url_naming_determination.rb', line 4 def @connection_options end |
#resource_klass ⇒ Object (readonly)
Returns the value of attribute resource_klass.
4 5 6 |
# File 'lib/remote_resource/url_naming_determination.rb', line 4 def resource_klass @resource_klass end |
Instance Method Details
#base_url(id = nil, check_collection_options: false) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/remote_resource/url_naming_determination.rb', line 11 def base_url(id = nil, check_collection_options: false) site = .fetch(:site, resource_klass.site) version = .fetch(:version, resource_klass.version) path_prefix = .fetch(:path_prefix, resource_klass.path_prefix) path_postfix = .fetch(:path_postfix, resource_klass.path_postfix) File.join(site.to_s, version.to_s, path_prefix.to_s, collection_prefix().to_s, url_safe_relative_name, id.to_s, path_postfix.to_s).chomp('/') end |
#collection_prefix(check_collection_options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/remote_resource/url_naming_determination.rb', line 20 def collection_prefix() prefix = .fetch(:collection_prefix, resource_klass.collection_prefix) if prefix.present? prefix = "/#{prefix}" unless prefix.chr == '/' = .fetch(:collection_options, {}).with_indifferent_access prefix.gsub(/:\w+/) do |key| value = .fetch(key[1..-1], nil) if value.nil? raise(RemoteResource::CollectionOptionKeyError, "`collection_prefix` variable `#{key}` is missing from `collection_options`") if value = key end URI.parser.escape(value.to_s) end end end |
#relative_name ⇒ Object
48 49 50 51 52 |
# File 'lib/remote_resource/url_naming_determination.rb', line 48 def relative_name collection_name = .fetch(:collection_name, resource_klass.collection_name) collection_name.to_s.presence || resource_klass.name.to_s.demodulize end |
#url_safe_relative_name ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/remote_resource/url_naming_determination.rb', line 38 def url_safe_relative_name collection = .fetch(:collection, resource_klass.collection) if collection relative_name.underscore.downcase.pluralize else relative_name.underscore.downcase end end |