Class: Geolocal::Configuration
- Inherits:
-
Object
- Object
- Geolocal::Configuration
- Defined in:
- lib/geolocal/configuration.rb
Constant Summary collapse
- OPTIONS =
[ :provider, :module, :file, :tmpdir, :ipv4, :ipv6, :quiet, :countries ]
Instance Method Summary collapse
-
#file ⇒ Object
if not set, defaults to lib/module-name.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_provider ⇒ Object
- #module_file(modname) ⇒ Object
- #require_provider_file ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/geolocal/configuration.rb', line 6 def initialize # configuration defaults @provider = 'Geolocal::Provider::DB_IP' @module = 'Geolocal' @file = nil # default is computed @tmpdir = 'tmp/geolocal' @ipv4 = true @ipv6 = true @quiet = false @countries = {} end |
Instance Method Details
#file ⇒ Object
if not set, defaults to lib/module-name
19 20 21 |
# File 'lib/geolocal/configuration.rb', line 19 def file @file || "lib/#{module_file @module}.rb" end |
#load_provider ⇒ Object
33 34 35 36 |
# File 'lib/geolocal/configuration.rb', line 33 def load_provider require_provider_file @provider.split('::').reduce(Module, :const_get) end |
#module_file(modname) ⇒ Object
43 44 45 |
# File 'lib/geolocal/configuration.rb', line 43 def module_file modname modname.gsub('::', '/').gsub(/([a-z])([A-Z])/, '\1_\2').downcase end |
#require_provider_file ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/geolocal/configuration.rb', line 23 def require_provider_file begin # normal ruby/gem load path Kernel.require module_file(@provider) rescue LoadError # used when running source code locally Kernel.require "./lib/#{module_file(@provider)}.rb" end end |
#to_hash ⇒ Object
38 39 40 41 |
# File 'lib/geolocal/configuration.rb', line 38 def to_hash # returned keys will always be symbols OPTIONS.reduce({}) { |a,v| a.merge! v => self.send(v) } end |