configatron
A super cool, simple, and feature rich configuration system for Ruby apps.
Mark Bates
Is there a way to avoid typing the namespace each time when using the configatron gem?
Say, you have
configatron.email.pop.address = 1
configatron.email.pop.port = 2
Can I configure port and address by somehow typing configatron.email.pop
only once?
Source: (StackOverflow)
I'm pretty new to Ruby (though not to programming) and am trying to create a persistent config. Though I thought using Configatron would automatically make my config persistent, it does not seem to be the case. How would I make this persistent throughout multiple runs? Should I store this to a file? If so, how? I would think a ~/.myapp
file might be good?
Source: (StackOverflow)
In my app I'm using configatron gem. The problem is I dont't understand clearly where I should store configatron settings. I put configatron.application_url = 'http://google.com/'
in config/configatron/defaults.rb but this is not working. In the view configatron.application_url
displays #<Configatron::Store:0x000001035afe70>
Source: (StackOverflow)
I'm using Logger through config and this line:
configatron.log.level = Logger::Warn
gives me the error:
`<top (required)>': uninitialized constant Logger::Warn (NameError)
Even if I require 'logger' at the top.
what gives?
< Ruby N00B >
Source: (StackOverflow)
I'm using configatron to store my config values. I can access the config values without a problem, except when the scope is within a class's method.
I'm using configatron 3.0.0-rc1 with ruby 2.0.0
Here is the source I'm using in a single file called 'tc_tron.rb'
require 'configatron'
class TcTron
def simple(url)
puts "-------entering simple-------"
p url
p configatron
p configatron.url
p configatron.database.server
puts "-------finishing simple-------"
end
end
# setup the configatron. I assume this is a singleton
configatron.url = "this is a url string"
configatron.database.server = "this is a database server name"
# this should print out all the stuff in the configatron
p configatron
p configatron.url
p configatron.database.server
# create the object and call the simple method.
a = TcTron.new
a.simple("called URL")
# this should print out all the stuff in the configatron
p configatron
p configatron.url
p configatron.database.server
When I run the code, I get
{:url=>"this is a url string", :database=>{:server=>"this is a database server name"}}
"this is a url string"
"this is a database server name"
-------entering simple-------
"called URL"
{}
{}
{}
-------finishing simple-------
{:url=>"this is a url string", :database=>{:server=>"this is a database server name"}}
"this is a url string"
"this is a database server name"
Between the 'entering simple' and 'finishing simple' output I don't know why I'm not getting the configatron singleton.
What am I missing?
Source: (StackOverflow)
I'm using the configatron gem for a new Rails app that is backed up by ActiveRecord. Some of my configatron settings are set in a file and some are pulled from DB, as they will change from time to time, here are a couple of lines from my configatron.rb
configatron.app.uptime.start = Time.now
configatron.email.signature = Setting.where(:keyname => "email_signature").first.value.to_s unless Setting.where(:keyname => "email_signature").first.nil?
Since this app sends multiple emails from multiple mailers - that is a good way to keep this global config in one place, plus it reduces db lookups for signature. If for some reason site admin decides to change it - they can do it through web admin interface that will update my settings table ( tied to Setting model).
This is all jolly & good, however what is the best place to store configatron.rb? Right now it's sitting in my initializers folder. Which means it will load once on application startup - which is good, however if one of the settings changes - site admin decides to tweak email signature to mention a new promotional website - in order for the change to take effect - I would need to restart app ( running passenger - so it trivial to do touch tmp/restart.txt
from code). However that means other configatron settings that I don't wont to reset ( such as my uptime start timestamp) will be reset as well.
So what is a better place to move my configatron.rb and load from so that it would allow for
loading once on startup and then changing some configs without and app restart?
Thanks.
Source: (StackOverflow)
I recently replaced a home-grown configuration module with Configatron, but I'm unable to get one use case working.
When I attempt to use a configatron value as an argument to Object.const_get like this:
def formatter_class
Object.const_get(configatron.formatter)
end
I get the following error:
file.rb:10:in `const_get': can't convert Configatron::Store to String
(Configatron::Store#to_str gives Configatron::Store) (TypeError)
The configatron assignment looks like this (simplified):
configatron.formatter = case
when condition?
'ExportFormat'
else
'ScreenFormat'
end
Even if I do configatron.formatter = 'ScreenFormat'
, I get the same error.
I've tried variations on the formatter_class
method too. This fails:
def formatter_class
Object.const_get(configatron['formatter'])
end
Of course, this succeeds, but won't fulfill my use case:
def formatter_class
Object.const_get('ScreenFormat')
end
What am I doing wrong?
Source: (StackOverflow)
If I'm setting up configuration for my ruby application logging using configatron
,
does anyone know how to:
1. Do Enum values, e.g.
configatron.log.level = 'DEBUG'
where other acceptable values such as ERROR, WARN, INFO. are forced and other values other than these are rejected?
2. Do multiple values e.g. configatron.log.logto = [:file, :udp, :stdout]
I'd like these values to be also enforceable.
Any clues appreciated.
Source: (StackOverflow)
I want to see test
and test2
configatron.providers.test.remote_dir = '/incoming/test/current'
configatron.providers.test.local_dir = 'data/test'
configatron.providers.test2.remote_dir = '/incoming/test2/current'
configatron.providers.test2.local_dir = 'data/test2'
configatron.providers.foreach do |p|
p.name() #<--- how to display test/test2
end
Tried reading the manual? did I miss this somewhere? Google was no help.
Thanks.
Source: (StackOverflow)
Case: Development environment log level is DEBUG while Production is INFO. I want to use every default log configuration and overwrite only level if environment == develoment.
Problem: first level configs can be over-written but not sub levels.
Consider Example Code:
#file: config.rb
default = Configuration.for('default'){
log {
file '/tmp/foo.log'
level 'WARN'
freq 'daily'
}
}
development = Configuration.for( 'development', default) {
log {
level 'DEBUG'
}
}
In main file, I use the above code like so
# main.rb
require 'config.rb'
$CONFIG = Configuration.for $DEV_ENV # either ('default' || 'development')
p $CONFIG.log.freq
I get an method missing error:
`undefined method `freq' for #<Configuration:0x00000003a65d80> (NoMethodError)`
The only (ugly) solution i have is to point file and freq values back to default like so:
log {
file default.log.file
level 'DEBUG'
freq default.log.freq
}
EEWWW!! Nasty!
Any other suggestions? I've tried to implement something like this with SettingsLogic and Configatron too at no avail. There goes the three top configuration gems for Ruby. Do I need to make my own?? Is this really such an exotic example?
Would love your feedback or suggestions.
Source: (StackOverflow)