class Fragments::Config

Contains a current config to request fragments properly

@author Sergey Gernyak

Attributes

host[RW]

Set or get a host to which request should be sent to get fragment's html structure

is_enabled[RW]

Specifies either fragments usage is enabled or not

uri_prefixes[RW]

Contains URL prefixes It should be a hash where:

  • key is a locale in ISO2 format

  • value is an URL prefix

Public Instance Methods

is_enabled=(value) click to toggle source

Setter for enableness flag @param value [Boolean] - A value of the flag @raise ArgumentError - when an invalid boolean value has been passed

# File lib/fragments/config.rb, line 36
def is_enabled=(value)
  raise ::ArgumentError, "Value should be a valid boolean one!" if !value.is_a?(TrueClass) && !value.is_a?(FalseClass)
  @is_enabled = value
end
uri_prefix(locale) click to toggle source

Provides an URI prefix for a given locale @param locale [String] - A locale for which URI prefix should be returned @return [String] an URI prefix

# File lib/fragments/config.rb, line 21
def uri_prefix(locale)
  uri_prefixes[normalize_key(locale)] || ""
end
uri_prefixes=(value) click to toggle source

Setter for the URI prefixes mapping hash @param value [Hash] - A hash with URI prefix per locale mappings @raise ArgumentError - when an invalid value has been passed

# File lib/fragments/config.rb, line 28
def uri_prefixes=(value)
  raise ::ArgumentError, "Value should be a valid Hash!" unless value.is_a?(Hash)
  @uri_prefixes = Hash[value.map { |k, v| [normalize_key(k), v] }]
end

Private Instance Methods

normalize_key(value) click to toggle source
# File lib/fragments/config.rb, line 50
def normalize_key(value)
  value.downcase.to_sym
end