has_settings 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,94 @@
1
- = has_settings
1
+ = Has settings
2
2
 
3
- Description goes here.
3
+ This is a slightly revised version of the features gem (http://github.com/zendesk/features/). This gem allows you to work with row oriented settings rather than having an ever increasing number of columns on your model table. You may want to check out alternative approaches for this, like e.g. the bit mask based ones such as https://github.com/xing/flag_shih_tzu
4
4
 
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
5
+ == Description
14
6
 
15
- == Copyright
7
+ You configure the allowed settings by specifying these in an initializer:
16
8
 
17
- Copyright (c) 2010 Morten Primdahl. See LICENSE for details.
9
+ class Account < ActiveRecord::Base
10
+ has_settings do
11
+ setting :forums
12
+ setting :wiki
13
+ end
14
+ end
15
+
16
+ These are the settings that can be used runtime. This enables code like:
17
+
18
+ account.settings.ssl? # checks whether an account has the ssl setting.
19
+ account.settings.ssl.create # adds the ssl setting to the account
20
+ account.settings.ssl.destroy # removes the ssl setting from the account
21
+
22
+ And that's pretty much it.
23
+
24
+ Settings can also be updated with the update_attributes and update_attributes! methods.
25
+
26
+ # assuming params include { :account => { :settings => { :wiki => '1', :forums => '0' } } }
27
+ account.update_attributes(params[:account]) # would add the wiki feature and remove the forums setting
28
+
29
+ We also created a view helper to help you generate the UI for enabling and disabling settings:
30
+
31
+ <% form_for(:account, :html => { :method => :put }) do |f| %>
32
+ <h3>
33
+ <%= f.settings_check_box :forums %> Enable forums on your account
34
+ </h3>
35
+ <% end %>
36
+
37
+ == Security
38
+
39
+ We support protection from mass updates, the syntax is as follows:
40
+
41
+ class Account < ActiveRecord::Base
42
+ has_settings do
43
+ setting :forums, :protected => true
44
+ setting :wiki
45
+ end
46
+ end
47
+
48
+ == Installation
49
+
50
+ Install the gem in your rails project by putting it in your Gemfile:
51
+
52
+ gem 'has_settings'
53
+
54
+ Also remember to create the settings table, if for example you are going to be using this with an accounts model, you can should the table like:
55
+
56
+ create_table :account_settings do |t|
57
+ t.integer :account_id, :null => false
58
+ t.string :name, :null => false
59
+ t.timestamps
60
+ end
61
+
62
+ add_index :account_settings, [ :account_id, :name ], :unique => true
63
+
64
+ == Requirements
65
+
66
+ * ActiveRecord
67
+ * ActionPack
68
+
69
+ == LICENSE:
70
+
71
+ (The MIT License)
72
+
73
+ Copyright (c) 2010 Zendesk
74
+
75
+ Permission is hereby granted, free of charge, to any person
76
+ obtaining a copy of this software and associated documentation
77
+ files (the "Software"), to deal in the Software without
78
+ restriction, including without limitation the rights to use,
79
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
80
+ copies of the Software, and to permit persons to whom the
81
+ Software is furnished to do so, subject to the following
82
+ conditions:
83
+
84
+ The above copyright notice and this permission notice shall be
85
+ included in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
88
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
89
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
90
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
91
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
92
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
94
+ OTHER DEALINGS IN THE SOFTWARE.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_settings}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
@@ -4,7 +4,7 @@ require 'has_settings/has_settings_helper'
4
4
 
5
5
  module HasSettings
6
6
  def self.ensure_settings_class(owner_class)
7
- const_name = "#{owner_class.name}Settings".to_sym
7
+ const_name = "#{owner_class.name}Setting".to_sym
8
8
  unless Object.const_defined?(const_name)
9
9
  settings_class = Object.const_set(const_name, Class.new(HasSettings::Setting))
10
10
  settings_class.owner_class = owner_class
@@ -6,7 +6,7 @@ module HasSettings
6
6
  settings_class.instance_eval(&block)
7
7
 
8
8
  has_many :settings, :class_name => settings_class.name, :dependent => :destroy do
9
- moo = settings_class
9
+
10
10
  def build(*setting_names)
11
11
  setting_names.each do |setting_name|
12
12
  self << settings_class.new(:name => setting_name)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_settings
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl