rubyconfig / config Goto Github PK
View Code? Open in Web Editor NEWEasiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.
License: Other
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.
License: Other
I've tried to run te test suite with Ruby 1.8.7 (REE) and I got this :
(the current commit is ec6f46d)
~/Sandbox/jlecour/rails_config [ree-1.8.7-2012.02][git:fix_symbols?]
→ be rake
/Users/jlecour/.rbenv/versions/ree-1.8.7-2012.02/bin/ruby -S rspec spec/rails_config_spec.rb spec/sources/yaml_source_spec.rb
FF......FF...........FFFF.............
Failures:
RailsConfig should load a basic config file
Failure/Error: config = RailsConfig.load_files(setting_path("settings.yml"))
TypeError:
nil is not a symbol
RailsConfig should load 2 basic config files
Failure/Error: config = RailsConfig.load_files(setting_path("settings.yml"), setting_path("settings2.yml"))
TypeError:
nil is not a symbol
RailsConfig should allow overrides
Failure/Error: config = RailsConfig.load_files(files)
TypeError:
nil is not a symbol
RailsConfig should allow full reload of the settings files
Failure/Error: RailsConfig.load_and_set_settings(files)
TypeError:
nil is not a symbol
RailsConfig Merging hash at runtime should be chainable
Failure/Error: let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
TypeError:
nil is not a symbol
RailsConfig Merging hash at runtime should preserve existing keys
Failure/Error: let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
TypeError:
nil is not a symbol
RailsConfig Merging hash at runtime should recursively merge keys
Failure/Error: let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
TypeError:
nil is not a symbol
RailsConfig Merging hash at runtime should rewrite a merged value
Failure/Error: let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
TypeError:
nil is not a symbol
Finished in 0.04651 seconds
38 examples, 8 failures
Failed examples:
rspec ./spec/rails_config_spec.rb:5 # RailsConfig should load a basic config file
rspec ./spec/rails_config_spec.rb:11 # RailsConfig should load 2 basic config files
rspec ./spec/rails_config_spec.rb:50 # RailsConfig should allow overrides
rspec ./spec/rails_config_spec.rb:57 # RailsConfig should allow full reload of the settings files
rspec ./spec/rails_config_spec.rb:161 # RailsConfig Merging hash at runtime should be chainable
rspec ./spec/rails_config_spec.rb:165 # RailsConfig Merging hash at runtime should preserve existing keys
rspec ./spec/rails_config_spec.rb:169 # RailsConfig Merging hash at runtime should recursively merge keys
rspec ./spec/rails_config_spec.rb:174 # RailsConfig Merging hash at runtime should rewrite a merged value
rake aborted!
/Users/jlecour/.rbenv/versions/ree-1.8.7-2012.02/bin/ruby -S rspec spec/rails_config_spec.rb spec/sources/yaml_source_spec.rb failed
If I try to run rake db:test:prepare
I get an error (ran it with --trace
):
** Invoke db:test:prepare (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
rake aborted!
uninitialized constant Settings
(erb):9:in `<main>'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `eval'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `result'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application/configuration.rb:106:in `database_configuration'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/railtie.rb:46:in `block (3 levels) in <class:Railtie>'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:197:in `block in invoke_prerequisites'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `each'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `invoke_prerequisites'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:174:in `block in invoke_with_call_chain'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/bin/rake:23:in `load'
/Users/jasperkennis/.rbenv/versions/2.0.0-p247/bin/rake:23:in `<main>'
Tasks: TOP => db:test:prepare => db:load_config
The problem goes away when I hardcode my db configurations. Breaking database.yml looks like this:
development:
host: localhost
adapter: postgresql
encoding: utf8
database: <%= Settings.databases.development.database %>
pool: 5
username: <%= Settings.databases.development.user %>
password:
test:
adapter: postgresql
encoding: utf8
database: <%= Settings.databases.test.database %>
pool: 5
username: <%= Settings.databases.development.user %>
password:
I'm om Rails 4, ruby 2.0.0p247, and rails_config 0.3.3. Don't really know why this is happening, I haven't noticed similar problems with any other tasks. Can provide more info if needed.
having rails_config in the project throws an error on start
/Users/jc/.rvm/gems/ruby-2.0.0-p247/bundler/gems/rails_config-a672a110738b/lib/rails_config/integration/rails.rb:8:in `block in <class:Railtie>': undefined method `join' for nil:NilClass (NoMethodError)
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.1.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/application.rb:121:in `initialize'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/railtie.rb:171:in `new'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/railtie.rb:171:in `instance'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/application.rb:90:in `inherited'
from /Users/jc/Projects/test/config/application.rb:25:in `<module:Contacts>'
from /Users/jc/Projects/test/config/application.rb:24:in `<top (required)>'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/commands/commands_tasks.rb:146:in `require'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/commands/commands_tasks.rb:146:in `require_application_and_environment!'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/jc/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.1.0.rc2/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
I'm not sure if this is a Rails3 issue, as I just started using Rails3, but I had a similar issue with Settingslogic last night on a Rails3 app.
I use a config for various settings in my environment configs, eg:
config.action_mailer.default_url_options = { :host => Settings.base.host }
With that being said, I get the following error:
uninitialized constant Settings
Is this the way the boot process works in Rails3?
Thanks!
I have
Exchange24::Application.configure do
config.action_mailer.default_url_options = { host: Settings.mail.host }
end
I start the server
block in <top (required)>': uninitialized constant Settings (NameError)
Was working fine in Rails 4.0.4
Any idea how to fix ?
Previously had rails 3.0.0.rc and rails_config 0.1.3. All working fine.
Installed Rails 3.0.0 release
Updated rails application Gemfile: gem 'rails', '3.0.0'
bundle install
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
rails (= 3.0.0) depends on
activesupport (= 3.0.0)
rails_config (= 0.1.3) depends on
activesupport (3.0.0.rc)
Sometimes I need a real hash within my Settings. For example:
prices:
1: 2.99
5: 9.99
15: 19.99
30: 29.99
I'd like to be able to access this setting via Settings.prices[1] #=> 2.99
However, this doesnt work since rails_config tries to convert everything to OpenStructs, and 1,5,15,etc do not work as method accessors.
Here's a workaround syntax:
prices:
type: hash
contents:
1: 2.99
5: 9.99
15: 19.99
30: 29.99
While parsing the settings, if there's a type:
field set to "hash", I'll assign the hash value in contents:
to the setting. So the previous settings will provide a config of Settings.prices #=> {1 => 2.99, 5 => 9.99, etc..}
Hi,
there are some problems with using this plugin on ruby 1.9.3 with rails 3.1.0. In logs i see message
NameError (uninitialized constant Settings)
1.9.3 is installed with following manual - http://joneslee85.wordpress.com/2011/02/10/another-attempt-to-compile-rvm-ruby-1-9-with-clang-2-0-xcode-4-0-on-mac-osx-10-6-6/
In config/settings.yml
:
foo: bar
In config/settings/development.yml
:
foo: bar_dev
In config/settings/test.yml
:
foo: bar_test
When i start the rails console in the development environment, i.e. rails console
, everything works as expected. The value of Settings.foo
equals bar_dev
.
However, if I start the rails console in the test environment, i.e. rails console -e test
, the value of Settings.foo
still equals bar_dev
. I would expect it to equal bar_test
.
I even tried Settings.reload!
, but the value remains bar_dev
when in the test environment.
Is this not working as expected, or am I missing something?
It seems that the generator has changed name.
$ bundle exec rails g rails_config:install
Could not find generator rails_config:install.
$ bundle exec rails g rails_config
create config/initializers/rails_config.rb
Also looking at the code I thought the generator should provide empty settings files, but it doesn't seem to
I'm using rails4.1.1 and Ruby2.0.0-p481
I try to use rails_config with capistrano.
and I wrote like this
require 'aws-sdk'
require 'yaml'
require 'rails_config'
RailsConfig.load_and_set_settings('config/settings.yml')
# settings
but the line 3, require "rails_config" raises error uninitialized constant Rails
.
I found to work this with rails_config0.3.
Is there any change in rails_config0.4 ?
Hello,
Since the recent commit (0.2.6): 1e7f860
I cannot evaluate Settings anymore, if I try to execute the rake task for assets:precompile (Rails 3.2.2) it bombs with
rake aborted!
uninitialized constant Settings
This is working fine in 0.2.5
.
config/environments/staging.rb
config.cache_store = :dalli_store, Settings.app.memcache.hosts
command
bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile --trace
It would be nice to have a method/feature that allows us to specify some settings as read-only, particularly as when I display the settings, there is a key/value that appears for each section as modifiable: true
. It seems that this is something to do with the options so if a shortcut could be provided to allow us to mark a section as modifiable or not at runtime, it would make it easier to manage sections.
Most of the open issues are out of date, and now fixed. Please close them.
/cc @railsjedi
Settings
is the name of the constant yet the gem name is rails_config
? Ahhh, this hurts so much!
ps: I don't expect this issue to be taken seriously, as it's mainly a complaint of seeing one thing (Settings
) and not knowing where it originates (rails_config
).
I'd like to utilize the power of rails_config to extend the storage of the key / value pairs in ActiveRecord databases. Is this possible with the existing code? Maybe if someone points me in the direction of where to add this functionality I may be able to extend this gem further with ActiveRecord support.
If I was to create a model with the same name of Settings, is it possible to default to ActiveRecord with the YAML files as fallback?
I'm a new on the whole rails scene so this might be a really newbie question, but I don't seem to be able to iterate through my Settings. I'm trying to iterate through Settings.navigation which could have another array under them.
With
<%= debug Settings.navigation %>
I get
--- !ruby/object:RailsConfig::Options
table:
:Book: !ruby/object:RailsConfig::Options
table:
:Add: TestBookAdd
:List: TestBookList
modifiable: true
:Users: !ruby/object:RailsConfig::Options
table:
:Add: TestUsersAdd
:View: TestUsersView
modifiable: true
modifiable: true
I'm trying to each them, but
<% debug Settings.navigation.each do |n| %>
<%= debug c %>
<% end %>
gives me nothing. I actually did find a way to iterate them, by first converting Settings.navigation to JSON and then parse that, but this seem so silly that there has the be a better way :) so:
<% JSON.parse(Settings.navigation.to_json).each do |n| %>
<%= debug n %>
<% end %>
gives me what I was expecting
---
- Book
- Add: TestBookAdd
List: TestBookList
---
- Users
- Add: TestUsersAdd
View: TestUsersView
So is there a better way to iterate through nested configs?
I'm sorry if this isn't the right place for this kind of questions :/
Hi,
In a Rails app, where I also use resque, multi_json, yajl alongside with rails_config, I get errors whenever I try to pass a RailsConfig::Options object to a Resque job.
The error Is like this :
LoadError (no such file to load -- json):
activesupport (3.0.7) lib/active_support/dependencies.rb:239:in `require'
activesupport (3.0.7) lib/active_support/dependencies.rb:239:in `require'
activesupport (3.0.7) lib/active_support/dependencies.rb:225:in `load_dependency'
activesupport (3.0.7) lib/active_support/dependencies.rb:596:in `new_constants_in'
activesupport (3.0.7) lib/active_support/dependencies.rb:225:in `load_dependency'
activesupport (3.0.7) lib/active_support/dependencies.rb:239:in `require'
rails_config (0.2.3) lib/rails_config/options.rb:52:in `to_json'
multi_json (1.0.3) lib/multi_json/engines/yajl.rb:14:in `encode'
multi_json (1.0.3) lib/multi_json/engines/yajl.rb:14:in `encode'
multi_json (1.0.3) lib/multi_json.rb:72:in `encode'
resque (1.19.0) lib/resque/helpers.rb:22:in `encode'
resque (1.19.0) lib/resque.rb:151:in `push'
resque (1.19.0) lib/resque/job.rb:48:in `create'
resque (1.19.0) lib/resque.rb:233:in `enqueue'
Thanks for any help
Crashes on generate if .gitignore file is missing
Rails 4.1 introduces a built-in convention for having a secrets.yml with secrets in it: http://edgeguides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml
It would be cool if this gem did some of these things:
Rails.application.secrets
to Settings.secrets
I think this gem is a better overall solution to managing configuration, but if Rails is making this a thing, it would make sense to go along with it and make this gem work nicely with the new stuff.
When using in a Sinatra app, RailsConfig crashes because module Rails is not defined:
rails_config-0.4.1/lib/rails_config/engine.rb:2:in `<module:RailsConfig>': uninitialized constant Rails (NameError)
Suggest to only include engine.rb when Rails is defined.
I'd like to add more files to the RailsConfig file load chain. I know what these files will be in advance, so I'd rather avoid loading them at runtime. Is there some syntax available that works like the following...
RailsConfig.setup do |config|
config.add_file(Rails.root.join("config", "some_additional_stuff.yml")
end
I didn't see anything whilst digging through the code, though I am admittedly n00bish when it comes to parsing out gems.
Hiya,
I'm using an optional YML file with additional options as well as changes to the existing ones, which is loaded if it exists (doing so via Settings.add_source!("#{Rails.root}/config/lpl.yml")
in my app's initializer). The problem is that I have the following defined in settings.yml:
lpl:
..
language_options:
- de
- en
..
while my own file has
lpl:
..
language_options:
- de
..
I was expecting the result to be that Settings.lpl.language_options
would hold ["de"]
, yet it still holds ["de", "en"]
. Do I need to do anything besides
if File.exists?("#{Rails.root}/config/lpl.yml")
Settings.add_source!("#{Rails.root}/config/lpl.yml")
Settings.reload!
end
when loading the additional settings in my initlializer? Or should I be unloading all settings and include all the settings in lpl.yml
, not just the ones that would add to/overwrite stuff from config.yml
? And if so—how?
Thanks! :)
config/settings/productions.yml
authentication:
password_expired_after: <%= 1.month %>
use_validate_code: true
after(:each) do
Rails.env = 'test'
end
it "should not use validate code at loign page during test env" do
Settings.authentication.use_validate_code.should == false
end
it "should not use validate code at loign page during development env" do
Rails.env = 'development'
Rails.env.should == 'development'
Settings.authentication.use_validate_code.should == false
end
it "should use validate code at loign page during production env" do
Rails.env = 'production'
Rails.env.should == 'production'
Settings.reload!
Settings.authentication.use_validate_code.should == true
end
The spec test can't passed:
Failures:
Apparently, this code here does not work on Rails 3.1
At rails_config/integration/rails.rb
if Rails.env.development?
initializer :rails_config_reload_on_development do
ActionController::Base.class_eval do
prepend_before_filter { ::RailsConfig.const_name.constantize.reload! }
end
end
end
When I upgrade from 0.2.5 to the most recent version, I'm now starting to get this error:
NameError: uninitialized constant AppName::Application::Settings
The offending line comes from app/config/application.rb
:
config.action_mailer.default_url_options = { host: Settings.host }
I believe the issue comes from a change in how RailsConfig is loaded, based off one of these two commits: 9e17fac and 1e7f860.
Is there any workaround for this?
gemfile:
gem "rails_config", '0.2.5'
i have configured secret token:
MySite::Application.config.secret_key_base = Settings.secret_token
In console i have:
2.0.0p353 :001 > Settings.secret_token => "9a1773c......."
the config/initializers/secret_token.rb is not present in my .gitignore
and i have configured SECRET_TOKEN on heroku:
$ heroku config:set SECRET_TOKEN=9a1773c.......
after heroku pushing , i try to open my app:
$ heroku open
but i have this response:
Internal Server Error You must set config.secret_key_base in your app's config.
if i hard-code the secret token it works:
MySite::Application.config.secret_key_base = "9a1773c......."
Ideas?
I added a rails_config gem into Gemfile, bundle install, wanted to run rails_config generator and it crashed. It also crashes when rails c or rails s with the same error.
Ruby 1.9.2 p290, rails 3.0.14 (apparently 1.9.2 and later does not have Fixnum#to_sym, but not sure what's the problem anyway)
/Users/robert/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/ostruct.rb:81:in new_ostruct_member': undefined method
to_sym' for 1:Fixnum (NoMethodError)
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:80:in block in __convert' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in
each'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in __convert' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:83:in
block in __convert'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in each' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in
__convert'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:83:in block in __convert' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in
each'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:79:in __convert' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/options.rb:31:in
reload!'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config.rb:30:in load_files' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config.rb:37:in
load_and_set_settings'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/bundler/gems/rails_config-1d0073df191e/lib/rails_config/integration/rails.rb:15:in block in <class:Railtie>' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/initializable.rb:25:in
instance_exec'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/initializable.rb:25:in run' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/initializable.rb:50:in
block in run_initializers'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/initializable.rb:49:in each' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/initializable.rb:49:in
run_initializers'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/application.rb:134:in initialize!' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/application.rb:77:in
method_missing'
from /Users/robert/projects/other/sport_centrum/config/environment.rb:5:in <top (required)>' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:242:in
require'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:242:in block in require' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:225:in
block in load_dependency'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:597:in new_constants_in' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:225:in
load_dependency'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/activesupport-3.0.14/lib/active_support/dependencies.rb:242:in require' from /Users/robert/projects/other/sport_centrum/config.ru:3:in
block in
instance_eval' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/builder.rb:46:in
initialize'new' from /Users/robert/projects/other/sport_centrum/config.ru:1:in
'eval' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/builder.rb:35:in
parse_file'app' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/server.rb:253:in
wrapped_app'start' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/commands/server.rb:65:in
start'block in <top (required)>' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/commands.rb:27:in
tap'<top (required)>' from script/rails:6:in
require'I was expecting to be able to "unset" a property in an overriding config file. For example, consider the following:
In config/settings.yml
name: Admin
email: [email protected]
In config/settings/development.yml
name: Nobody
email: null
However, it looks like instead of unsetting the value, the derived property is untouched.
That is, the above case yields:
Settings.name # => Nobody
Settings.email # => [email protected]
Rather than what I was expecting:
Settings.name # => Nobody
Settings.email # => nil
Bug, or feature?
Engine.isolate_namespace
exists in Rails 3.1+ only, so probably it worth to warn people about Rails compatibility :D
This's my code:
cities:
- "杭州市":
class City < ActiveRecord::Base
class << self
def directory
@active_cities = []
Settings.cities.each do |name|
#active_cities << find_by_name('')
@active_cities << where(name: name).first
end
@active_cities
end
end
end
If I remove RailsConfig, it does work:
class City < ActiveRecord::Base
class << self
def directory
@active_cities = []
['杭州市'].each do |name|
#active_cities << find_by_name('')
@active_cities << where(name: name).first
end
@active_cities
end
end
end
if you try to use Settings in environments/.rb, then it says "undefined constant Settings"
Hi,
Perhaps I'm missing how, as I've inspected the objects and looked through the source, but can't find it. I have an api section in my config:
Settings.api.gateways.paypal
This holds the config for our Paypal interface. I wanted to be able to do something similar:
@gw ||= Gateway.factory(:paypal, Settings.api.gateways.paypal)
Unfortunately I don't see a way to convert to a hash. I also can't find much on converting an Openstruct to a hash.
Have any suggestions?
Hello, I have this error when using ruby 1.9.2.
This gem looks great! I am currently using Figaro gem because it supports Heroku... wondering how this would support Heroku if already supported?
Hi,
RailsConfig has been quite stale for many month : only a handful of commits during the last year, almost no issue closed, …
Maybe it's a good time to evaluate the most important open issues and try to solve them then release a 1.0 version.
A piece of software, used by many in production for a long time, can't really stay in 0.x forever.
Plus, it might never be perfectly bug free and feature complete, but the life of project doesn't stop at 1.0.
FInally, according to SemVer semantics, marking a 1.0 release is a strong indication that the public API is stable (until 2.0) and is trusted to be used in production.
What do you think about that
Hi!
I just switched to RailsConfig from SettingsLogic and I really like it, apart from a small issue, that might well be a misunderstanding from my side, namely,
in config/initializers/rails_config.rb
, I had the following code:
RailsConfig.setup do |config|
config.const_name = "LplSettings"
end
—since my SettingsLogic class was named LplSettings and I thought that this would make the constant I'm accessing my settings trough named the same and thus make my transition easier. Am I right in assuming that the above code would made my settings accessible via LplSettings
instead of just Settings
? Settings
works and I managed to do a search & replace that didn't break anything. But I'm still wondering if it's working as designed or not. I even renamed the RailsConfig initalizer with a "01_" prefix to make sure it is initialized first, to no avail.
Thanks for the work on RailsConfig, have a nice day/evening.
Samo
Hi,
today i migrated our existing rails configuration to rails_config gem.
we had a several hundred lines long YAML-file that we accessed using the following syntax:
config['root_key.sub_key']
during the migration i had problems with following keys:
root:
id: 1
'google.com': 2
Settings.root.id => actually called object#id
Settings.root.google.com => :)
maybe we can change this in the future?
cheers,
--dpree
Is there any reason why Settings can be used in development.rb/production.rb, but can't be used in applicaiton.rb? I need to set some config the same way for all environments and wouldn't like to duplicate it for each of the environment files.
I use this:
photos: upload: photo_avatar_size: [60, 60]
And I get array with 1 element:
irb(main):001:0> Settings.photos.upload.photo_avatar_size => [60]
Is it bug?
rails_config (0.3.1)
Hi,
I hope this issue's title doesn't seem aggressive, anyway it's not the intention ;-)
For a long time, I've been checking for particular setting like this :
affiliate_id = begin
Settings.tracking.affiliate_id.send(options[:aid])
rescue NoMethodError, TypeError, ArgumentError => ex
Settings.tracking.affiliate_id.default
end
Today — I don't think my version has changed (0.2.x) — I get nil
for a missing setting, instead of a NoMethodError
exception.
I was surprised not to find any test case for this in the current 0.3.1
. I even wanted to add one, but i've had issues with Ruby 1.8 compatibility (hence my pull request and my #42 issue).
Am I crazy and it has always been that way?
Am I using it wrong?
Anyway, thanks for your help and for making/maintaining this great gem.
https://github.com/railsjedi/rails_config/blob/master/spec/fixtures/custom_types/hash.yml
It would be beneficial to mention this kind of structure in the README
If the settings.yml
file contains an array of key/value pairs then the to_hash
method skips over those pairs and fails to convert them even though it works for simple arrays.
For example, if the settings.yml
contains,
media:
types:
- Video
- Image
- Website URL
- Document
metadata:
- name: Field 1
type: string
required: true
- name: Field 2
type: tag
required: false
- name: Field 3
type: text
- name: Field 4
then calling Settings.media.to_hash
results in,
{:types=>["Video", "Image", "Website URL", "Document"], :metadata=>[#<RailsConfig::Options name="Field 1", type="string", required=true>, #<RailsConfig::Options name="Field 2", type="tag", required=false>, #<RailsConfig::Options name="Field 3", type="text">, #<RailsConfig::Options name="Field 4">]}
The correct output should probably be,
{:types=>["Video", "Image", "Website URL", "Document"], :metadata=>[{:name=>"Field 1", :type=>"string", :required=>true}, {:name=>"Field 2", :type=>"tag", :required=>false}, {:name=>"Field 3", :type=>"text"}, {:name=>"Field 4"}]}
Hi!
I know, there was some issues like that before, but it looks that it happen again. Works for me with 0.2.5, broken above. Ruby 1.9.2, rails 3.2.2
/path/to/project/config/environments/development.rb:33:in `block in <top (required)>': uninitialized constant Settings (NameError)
I tried to implement a settings as follows:
threshold: <%=10.megabytes%>
max: <%=1.gigabyte%>
...but it doesn't seem to be supported. Not using ERB tags results in a string.
This really seemed like a perfect gem for me. I extactly wanted specification for different environments in separate files.
However, there is one major design flaw. Accessing an option that wasn't set in the YAML files should raise a NoMethodError
. That is, RailsConfig::Options
shouldn't be an OpenStruct
. Otherwise there is no way to guard yourself from typos, since there is no way to determine whether you made one. And that can cause really hard-to-find bugs (e.g. boolean value like Settings.use_secure_sever
).
I am using rails_config and I wanted to namespace the constant used. However, this is not possible using the standard methods.
Also, when a different constant name than 'Settings' is used, all my controllers break in development mode as line 24 of railtie.rb specifically uses the Settings constant, but only in development mode.
I have worked around this in my app, but just wanted to let you know for future versions.
Thanks
Gary
NameError in AppsController#index
uninitialized constant Settings
/Users/kain/.rvm/gems/ruby-head/bundler/gems/rails-84763047a03e/activesupport/lib/active_support/inflector/methods.rb:221:in `block in constantize'
/Users/kain/.rvm/gems/ruby-head/bundler/gems/rails-84763047a03e/activesupport/lib/active_support/inflector/methods.rb:220:in `each'
/Users/kain/.rvm/gems/ruby-head/bundler/gems/rails-84763047a03e/activesupport/lib/active_support/inflector/methods.rb:220:in `constantize'
/Users/kain/.rvm/gems/ruby-head/bundler/gems/rails-84763047a03e/activesupport/lib/active_support/core_ext/string/inflections.rb:42:in `constantize'
rails_config (0.2.4) lib/rails_config/integration/rails.rb:30:in `block (3 levels) in <class:Railtie>'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.