Class: MusicBrainz::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/musicbrainz/configuration.rb

Constant Summary collapse

DEFAULT_WEB_SERVICE_URL =
"http://musicbrainz.org/ws/2/"
DEFAULT_QUERY_INTERVAL =
1.5
DEFAULT_TRIES_LIMIT =
5
DEFAULT_CACHE_PATH =
File.join(File.dirname(__FILE__), "..", "tmp", "cache")
DEFAULT_PERFORM_CACHING =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration


15
16
17
18
19
20
21
# File 'lib/musicbrainz/configuration.rb', line 15

def initialize
  @web_service_url = DEFAULT_WEB_SERVICE_URL
  @query_interval = DEFAULT_QUERY_INTERVAL
  @tries_limit = DEFAULT_TRIES_LIMIT
  @cache_path = DEFAULT_CACHE_PATH
  @perform_caching = DEFAULT_PERFORM_CACHING
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def app_version
  @app_version
end

#cache_pathObject

Returns the value of attribute cache_path


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def cache_path
  @cache_path
end

#contactObject

Returns the value of attribute contact


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def contact
  @contact
end

#perform_cachingObject

Returns the value of attribute perform_caching


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def perform_caching
  @perform_caching
end

#query_intervalObject

Returns the value of attribute query_interval


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def query_interval
  @query_interval
end

#tries_limitObject

Returns the value of attribute tries_limit


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def tries_limit
  @tries_limit
end

#web_service_urlObject

Returns the value of attribute web_service_url


4
5
6
# File 'lib/musicbrainz/configuration.rb', line 4

def web_service_url
  @web_service_url
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/musicbrainz/configuration.rb', line 23

def valid?
  %w[ app_name app_version contact ].each do |param|
    unless instance_variable_defined?(:"@#{param}")
      raise Exception.new("Application identity parameter '#{param}' missing")
    end
  end
  unless tries_limit.nil? && query_interval.nil?
    raise Exception.new("'tries_limit' parameter must be 1 or greater") if tries_limit.to_i < 1
    raise Exception.new("'query_interval' parameter must be greater than zero") if query_interval.to_f < 0
  end
  if perform_caching
    raise Exception.new("'cache_path' parameter must be set") if cache_path.nil?
  end
  true
end