Skip to content

Instantly share code, notes, and snippets.

@tsmango
Created August 31, 2011 01:32
Show Gist options
  • Select an option

  • Save tsmango/1182604 to your computer and use it in GitHub Desktop.

Select an option

Save tsmango/1182604 to your computer and use it in GitHub Desktop.
class Category < ActiveRecord::Base
configure do
option :sort do
default 'alphabetical'
restrict 'alphabetical', 'manual'
end
option :limit do
format 'fixnum'
end
option :price_filter do
format 'float'
modifiers 'eq', 'lt', 'gt', 'lte', 'gte'
multiple true
end
end
end
>> category = Category.create(:name => 'Vinyl Records')
=> #<Category id: 1, name: "Vinyl Records", created_at: "2011-08-03 15:46:11", updated_at: "2011-08-03 15:46:11">
?> category.settings
=> #<ActiveConfiguration::SettingManager:0x10e7d1950 @configurable=#<Category id: 1, name: "Vinyl Records", created_at: "2011-08-03 15:46:11", updated_at: "2011-08-03 15:46:11">>
?> category.settings[:sort]
=> {:value=>"alphabetical", :modifier=>nil}
?> category.settings[:sort][:value]
=> "alphabetical"
?> category.settings[:sort][:value] = 'manual'
=> "manual"
?> category.settings[:price_filter]
=> []
?> category.settings[:price_filter] = [{:modifier => 'gt', :value => 10.00}, {:modifier => 'lte', :value => 25.00}]
=> [{:value=>10.0, :modifier=>"gt"}, {:value=>25.0, :modifier=>"lte"}]
?> category.save
=> true
?> category.settings[:sort][:value]
=> "manual"
?> category.settings[:price_filter]
=> [{:value=>10.0, :modifier=>"gt"}, {:value=>25.0, :modifier=>"lte"}]
rails g active_configuration:install
gem 'active_configuration'
rake db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment