Class: Kangaroo::Util::Configuration
- Inherits:
-
Object
- Object
- Kangaroo::Util::Configuration
- Defined in:
- lib/kangaroo/util/configuration.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#database ⇒ Object
Returns the value of attribute database.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#models ⇒ Object
Returns the value of attribute models.
Instance Method Summary collapse
-
#configure_by_file(filename) ⇒ Object
Configure Kangaroo by YAML file.
-
#configure_by_hash(config) ⇒ Object
Configure Kangaroo by Hash.
-
#configure_database(db_config) ⇒ Object
Configure an OpenERP database.
-
#initialize(config_file_or_hash, logger = Logger.new(STDOUT)) ⇒ Configuration
constructor
Initialize the Kangaroo configuration.
-
#load_models ⇒ Object
Load configured models with Loader.
-
#login ⇒ Object
Login to the configured database.
Constructor Details
#initialize(config_file_or_hash, logger = Logger.new(STDOUT)) ⇒ Configuration
Initialize the Kangaroo configuration
15 16 17 18 19 20 21 22 23 |
# File 'lib/kangaroo/util/configuration.rb', line 15 def initialize config_file_or_hash, logger = Logger.new(STDOUT) @logger = logger case config_file_or_hash when String configure_by_file config_file_or_hash when Hash configure_by_hash config_file_or_hash end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/kangaroo/util/configuration.rb', line 9 def client @client end |
#database ⇒ Object
Returns the value of attribute database.
9 10 11 |
# File 'lib/kangaroo/util/configuration.rb', line 9 def database @database end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/kangaroo/util/configuration.rb', line 9 def logger @logger end |
#models ⇒ Object
Returns the value of attribute models.
9 10 11 |
# File 'lib/kangaroo/util/configuration.rb', line 9 def models @models end |
Instance Method Details
#configure_by_file(filename) ⇒ Object
Configure Kangaroo by YAML file
43 44 45 |
# File 'lib/kangaroo/util/configuration.rb', line 43 def configure_by_file filename configure_by_hash YAML.load_file(filename) end |
#configure_by_hash(config) ⇒ Object
Configure Kangaroo by Hash
53 54 55 56 |
# File 'lib/kangaroo/util/configuration.rb', line 53 def configure_by_hash config @client = Client.new config.slice('host', 'port') configure_database config['database'] end |
#configure_database(db_config) ⇒ Object
Configure an OpenERP database
65 66 67 68 69 |
# File 'lib/kangaroo/util/configuration.rb', line 65 def configure_database db_config @database = Database.new @client, *db_config.values_at('name', 'user', 'password') @models = db_config['models'] logger.info %Q(Configured OpenERP database "#{db_config['name']}" at "#{client.connection.host}") end |
#load_models ⇒ Object
Load configured models with Loader
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kangaroo/util/configuration.rb', line 27 def load_models if models.blank? logger.info "No models to load." return end login Loader.new(models, @database).load! logger.info "Loaded OpenERP models matching #{models.inspect}." rescue Exception => e logger.error "Loading of OpenERP models failed.\n#{e.inspect}" end |
#login ⇒ Object
Login to the configured database
73 74 75 76 77 78 79 |
# File 'lib/kangaroo/util/configuration.rb', line 73 def login if @database.login logger.info %Q(Authenticated user "#{@database.user}" for OpenERP database "#{@database.db_name}") else logger.warn %Q(Login to OpenERP database "#{@database.db_name}" with user "#{@database.user}" failed!) end end |