real_settings 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,6 +39,16 @@ Settings.config do
39
39
  # add some settings here
40
40
  end
41
41
  ```
42
+
43
+ ## Caution: settings in config/initializers/real_settings.rb can't store in database.
44
+
45
+ ```ruby
46
+ Settings.app_name # => "real_settings"
47
+ Settings.app_name = "new app name"
48
+ Settings.app_name # => "new app name"
49
+ Settings.save!
50
+ Settings.app_name # => "real_settings"
51
+ ```
42
52
 
43
53
  ## Features & Usage
44
54
 
@@ -126,15 +136,19 @@ Settings.admin_name # => "Macrow"
126
136
  ### Editing Global Settings
127
137
 
128
138
  ```ruby
139
+ # config/routes.rb
140
+ get 'settings/edit' => 'settings#edit'
141
+ put 'settings/update' => 'settings#update'
142
+
129
143
  # Edit Form:
130
- form_for(Settings) do |f|
144
+ form_for Settings, :as => :settings, :url => settings_update_path, :method => :put do |f|
131
145
  f.text_field :app_name
132
146
  f.text_field :app_url
133
147
  ......
134
148
  end
135
149
 
136
150
  # Update Action:
137
- Settings.update_attributes(params[:settings])
151
+ Settings.update_settings(params[:settings])
138
152
  ```
139
153
 
140
154
  ### Editing User's settings
@@ -155,7 +169,7 @@ end
155
169
 
156
170
  # Update Action:
157
171
  @user = User.find(params[:user_id])
158
- @user.settings.update_attributes(params[:settings])
172
+ @user.settings.update_settings(params[:settings])
159
173
  ```
160
174
 
161
175
 
@@ -1,3 +1,5 @@
1
+ # Caution: settings in config/initializers/real_settings.rb can't store in database.
2
+
1
3
  Settings.config do |settings|
2
4
  # settings.app_name = "My Application Name"
3
5
  # settings.app_url = "http://www.my-application.com"
@@ -16,7 +16,7 @@ class OwnerSettings < Settings
16
16
  end
17
17
 
18
18
  def to_hash
19
- @@__owner_default_settings[owner_type_symbol].merge(__settings)
19
+ @@__owner_default_settings[owner_type_symbol].merge(__settings).dup
20
20
  end
21
21
 
22
22
  def target_id
@@ -11,10 +11,10 @@ class Settings < ActiveRecord::Base
11
11
  end
12
12
 
13
13
  def to_hash
14
- __settings
14
+ __settings.dup
15
15
  end
16
16
 
17
- def update_attributes(attributes)
17
+ def update_settings(attributes)
18
18
  if attributes.nil?
19
19
  false
20
20
  else
@@ -1,3 +1,3 @@
1
1
  module RealSettings
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -63,6 +63,25 @@ describe "RealSettings" do
63
63
  Settings.another_name.should == 'new name'
64
64
  end
65
65
 
66
+ it "update settings from hash" do
67
+ hash = Settings.to_hash
68
+ hash[:new_feature_from_update_settings] = 'new_feature_from_update_settings'
69
+ Settings.new_feature_from_update_settings.should == nil
70
+ Settings.update_settings(hash)
71
+ Settings.new_feature_from_update_settings.should == 'new_feature_from_update_settings'
72
+ Settings.reload!
73
+ Settings.new_feature_from_update_settings.should == 'new_feature_from_update_settings'
74
+ end
75
+
76
+ it "settings in config/initializers/real_settings.rb can't store in database" do
77
+ Settings.app_name = 'new name'
78
+ Settings.app_name.should == 'new name'
79
+ Settings.save!
80
+ Settings.app_name.should == @app_name
81
+ Settings.reload!
82
+ Settings.app_name.should == @app_name
83
+ end
84
+
66
85
  it "has_settings without default values" do
67
86
  @account1 = Account.create!(:name => 'account1')
68
87
  @account1.settings.to_hash.should == {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: