Class: Heroics::Configuration

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

Overview

Attempts to load configuration, provides defaults, and provide helpers to access that data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
25
26
27
28
29
# File 'lib/heroics/configuration.rb', line 21

def initialize
  @options = {}
  @options[:cache] = 'Moneta.new(:Memory)'
  @options[:default_headers] = {}

  @ruby_name_replacement_patterns = { /[\s-]+/ => '_' }

  yield self if block_given?
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def base_url
  @base_url
end

#cache_pathObject

Returns the value of attribute cache_path.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def cache_path
  @cache_path
end

#module_nameObject

Returns the value of attribute module_name.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def module_name
  @module_name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def options
  @options
end

#ruby_name_replacement_patternsObject

Returns the value of attribute ruby_name_replacement_patterns.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def ruby_name_replacement_patterns
  @ruby_name_replacement_patterns
end

#schemaObject

Returns the value of attribute schema.



6
7
8
# File 'lib/heroics/configuration.rb', line 6

def schema
  @schema
end

Class Method Details

.defaultsObject



13
14
15
# File 'lib/heroics/configuration.rb', line 13

def self.defaults
  @defaults ||= Configuration.new
end

.restore_defaultsObject



17
18
19
# File 'lib/heroics/configuration.rb', line 17

def self.restore_defaults
  @defaults = Configuration.new
end

Instance Method Details

#headers=(headers) ⇒ Object



51
52
53
54
# File 'lib/heroics/configuration.rb', line 51

def headers=(headers)
  raise "Must provide a hash of headers" unless headers.is_a?(Hash)
  @options[:default_headers] = headers
end

#schema_filepath=(schema_filepath) ⇒ Object



35
36
37
# File 'lib/heroics/configuration.rb', line 35

def schema_filepath=(schema_filepath)
  @schema = Heroics::Schema.new(MultiJson.decode(open(schema_filepath).read))
end