Giter Club home page Giter Club logo

config's People

Contributors

albertosaurus avatar amatsuda avatar atatb avatar betamatt avatar cjlarose avatar cryo28 avatar eksoverzero avatar eugenk avatar fredwu avatar hallelujah avatar hanachin avatar inouetakuya avatar jcnetdev avatar jrafanie avatar m-nakamura145 avatar masterkain avatar merbjedi avatar neilwilliams avatar ojab avatar pkuczynski avatar qnighy avatar rdodson41 avatar rdubya avatar robertcigan avatar seikichi avatar slicedpan avatar soartec-lab avatar spalladino avatar tomkersten avatar ytkg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

config's Issues

not working with Rails 4.1.0.rc2

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'

secret token not recognized by heroku.

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?

Rails 4.1.0 configuration error

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 ?

to_hash method doesn't handle YAML arrays of key/value pairs

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"}]}

When did a missing setting started to return nil ?

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.

Tests don't pass with Ruby 1.8

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:

  1. RailsConfig should load a basic config file
    Failure/Error: config = RailsConfig.load_files(setting_path("settings.yml"))
    TypeError:
    nil is not a symbol

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:6

  2. 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

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:12

  3. RailsConfig should allow overrides
    Failure/Error: config = RailsConfig.load_files(files)
    TypeError:
    nil is not a symbol

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:52

  4. RailsConfig should allow full reload of the settings files
    Failure/Error: RailsConfig.load_and_set_settings(files)
    TypeError:
    nil is not a symbol

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./lib/rails_config.rb:37:in`load_and_set_settings'

    ./spec/rails_config_spec.rb:59

  5. 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

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:158

    ./spec/rails_config_spec.rb:162

  6. 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

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:158

    ./spec/rails_config_spec.rb:166

    ./spec/rails_config_spec.rb:166

  7. 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

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:158

    ./spec/rails_config_spec.rb:170

  8. 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

    ./lib/rails_config/options.rb:81:in `__convert'

    ./lib/rails_config/options.rb:79:in`each'

    ./lib/rails_config/options.rb:79:in `__convert'

    ./lib/rails_config/options.rb:31:in`load!'

    ./lib/rails_config.rb:30:in `load_files'

    ./spec/rails_config_spec.rb:158

    ./spec/rails_config_spec.rb:175

    ./spec/rails_config_spec.rb:175

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

Openstruct hash functionality

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?

Option overwriting doesn't work (for me, at least)

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! :)

Integration with encrypted Rails credentials

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:

  • Aliased Rails.application.secrets to Settings.secrets
  • Shimmed the secrets.yml functionality in for Rails < 4.1
  • Allowed you to have a secrets.local.yml or config/secrets/production.yml that behave the same way as the existing conventions do for non-secrets files

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.

Method to specify some settings as read-only

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.

Settings not defined before rake db:test:prepepare

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.

Iterating through Settings

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 :/

Cannot visit RailsConfig::Options

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

Using rails_config in config/environments/*.rb

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)

Using rails_config in config/environments/*.rb

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!

Readme incorrect

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

Add more YAML files at load time (not runtime)

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.

uninitialized constant Settings

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

bundle install fails with Rails 3.0.0

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)

Issue on ruby-head / rails (master)

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>'

Either I'm misunderstanding config.const_name, or it's not working (for me at least)

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

Using different constant names

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

ActiveRecord support

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?

OH GOD CHANGE THE NAME!

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).

Add Ability to Opt out of OStruct conversion

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..}

Missing keys should raise an error

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).

Currently some keys (e.g. "id" or "domain.tld") are critical

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

Multi-environment settings not loading properly

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?

broken during assets precompilation

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

Going 1.0

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

NameError: uninitialized constant AppName::Application::Settings

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?

[Question] Raise Uninitialize constant Rails in deploy.rb

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 ?

How to test config value in production evn?

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:

  1. #<RailsConfig::Options authentication=#<RailsConfig::Options password_expired_after=2592000, use_validate_code=false>> should use validate code at loign page during production env
    Failure/Error: Settings.authentication.use_validate_code.should == true
    expected: true,
    got: false (using ==)

    ./spec/models/settings_spec.rb:49:in `block (2 levels) in <top (required)>'

JSON error with resque and multi_json

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

Settings and application.rb

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.

Dup values in array converted to one

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)

Overloading with nulls

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?

Prevents loading env. / crashes

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 methodto_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:ineach'
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:inblock 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:ineach'
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:inreload!'
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:inload_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:ininstance_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:inblock 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:inrun_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:inmethod_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:inrequire'
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:inblock 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:inload_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:inblock in

'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/builder.rb:46: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:ininitialize'
from /Users/robert/projects/other/sport_centrum/config.ru:1:in new' from /Users/robert/projects/other/sport_centrum/config.ru:1:in'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/builder.rb:35:in eval' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/builder.rb:35:inparse_file'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/server.rb:162:in app' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/server.rb:253:inwrapped_app'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/rack-1.2.5/lib/rack/server.rb:204:in start' from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/commands/server.rb:65:instart'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/commands.rb:30:in 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:intap'
from /Users/robert/.rvm/gems/ruby-1.9.2-p290@sport_centrum/gems/railties-3.0.14/lib/rails/commands.rb:27:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `'

Crashes when loading in a Sinatra app

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.