Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added model-level settings #13

Merged
merged 7 commits into from Jul 21, 2012

Conversation

Projects
None yet
5 participants
Contributor

jimryan commented Dec 22, 2011

I added the ability to store model-wide settings, like so:

User.settings.foo = 'bar'

Which are inherited by instances of that class:

User.find(123).settings.foo => 'bar'

Inheritance now looks like this: default -> model -> object

So, if the setting doesn't exist on the object or the model, you'll get the default, as expected:

Settings.defaults['some_default'] = 'foo'
User.settings.some_default => 'foo'
User.find(123).settings.some_default => 'foo'

Contributor

jimryan commented Jan 11, 2012

Added a couple of other features that I had worked on previously on another rails-settings fork.

#settings= method to set settings in bulk by passing a hash

user.settings = { :foo => 'bar', :something => 'else' }
user.settings[:foo] # => 'bar'
user.settings[:something] # => 'else'

#all now returns defaults as well

Settings.defaults[:apples] = 'red'
Settings.defaults[:oranges] = 'orange'
user.settings[:apples] = 'green' # overriding a default
user.settings[:limes] = 'green'

user.settings.all # => { :oranges => 'orange', :apples => 'green', :limes => 'green' }
@jimryan jimryan Update test for #settings= to clarify that it does not replace all se…
…ttings and that it overwrites existing settings
1b0057e
Owner

jimryan commented on 1b0057e Jan 11, 2012

Just wanted to update this test to clarify that #settings= merges in the hash passed to it, it doesn't replace all settings with it.

sebicas commented Jan 27, 2012

Amazing modification, just what I was looking for! Thx!

Contributor

jimryan commented Jan 27, 2012

Thanks! Glad you like it!

Yeah, thanks Jim.

+1 for committing this pull. The hash merge is a much-needed feature!

@ledermann ledermann merged commit 1b0057e into ledermann:master Jul 21, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment