Class: Freebase::Api::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/freebase/api.rb

Overview

the configuration class controls access to the freebase.yml configuration file. it will load the rails-environment specific configuration

Constant Summary collapse

DEFAULTS =
{:host => 'sandbox.freebase.com', :debug => true, :trace => false}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



119
120
121
122
# File 'lib/freebase/api.rb', line 119

def initialize
  @configuration = {}.reverse_merge!(DEFAULTS)
  configure_rails if defined?(RAILS_ROOT)
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



115
116
117
# File 'lib/freebase/api.rb', line 115

def filename
  @filename
end

Instance Method Details

#[](k) ⇒ Object



141
142
143
# File 'lib/freebase/api.rb', line 141

def [](k)
  @configuration[k]
end

#[]=(k, v) ⇒ Object



137
138
139
# File 'lib/freebase/api.rb', line 137

def []=(k,v)
  @configuration[k] = v
end

#configure_railsObject



124
125
126
127
128
129
130
131
# File 'lib/freebase/api.rb', line 124

def configure_rails
  @filename = "#{RAILS_ROOT}/config/freebase.yml"
  unless File.exists? @filename
    puts "WARNING: #{RAILS_ROOT}/config/freebase.yml configuration file is not found. Using sandbox.freebase.com." 
  else
    set_all YAML.load_file(@filename)[RAILS_ENV].symbolize_keys!
  end
end

#set_all(opts = {}) ⇒ Object



133
134
135
# File 'lib/freebase/api.rb', line 133

def set_all(opts = {})
  opts.each {|k,v| self[k] = v}
end