settings_on_rails 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b83c9ecc5fb868616dcd1708d3f5b1c6efec936
4
- data.tar.gz: 8a1e64c5f65a24383fab856200b48d4acc0bdb67
3
+ metadata.gz: d01e255a35c506e47539e153ae23cabb903e9c52
4
+ data.tar.gz: 6e573d6f5554b495193174535a6998f027124eb0
5
5
  SHA512:
6
- metadata.gz: 0331b4b06617abc42b1b30bb5ad595bfc3db21b121ff8b795a57e32750c6e29e6b2499a79b7dc41d3d9266befbdca74e0788e7f7eb8d0663578606f3f6e24b29
7
- data.tar.gz: c91c95f9240c83ec946573063658cc3137f80b31af6444818dfa1ecdb5eb317f588363fa01589730ff369992193faf77c9e2ca3f94b33cefa45ff025f403f80d
6
+ metadata.gz: fc44c017dd98bcb5b3d91a7c58fd4b948efc4a2f0da732da57c610150e26d87a230277fbc7a5c7e7bf28a96cedc482249759f24e70c59ca4d2e961cf5bcd2eb9
7
+ data.tar.gz: 845f2459c7dd562f200fd1a3c4935d0c8980b856284ce37233bab13bbd46b5752344493f7a8590716a0cc1aa8b10b129dc5d0a072ae59026ded05a6dd1e4816f
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ If you are using [Bundler](http://bundler.io/), add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'settings_on_rails'
@@ -14,26 +14,30 @@ And then execute:
14
14
 
15
15
  $ bundle
16
16
 
17
- Or install it yourself as:
17
+ Alternatively, install it by running:
18
18
 
19
19
  $ gem install settings_on_rails
20
20
 
21
21
  ## Getting Started
22
22
 
23
- Start off by adding a text field to the model which you want it to have settings
23
+ ### Add database column
24
+
25
+ Start by adding a text field to the model on which you want settings:
26
+
24
27
  ```ruby
25
28
  rails g migration add_settings_column_to_blogs settings_column:text
26
-
27
29
  ```
28
30
 
29
- Declare in model
31
+ ### Declare in model
32
+
30
33
  ```ruby
31
34
  class Blog < ActiveRecord::Base
32
35
  has_settings_on :settings_column
33
36
  end
34
37
  ```
35
38
 
36
- Set settings
39
+ ### Set settings
40
+
37
41
  ```ruby
38
42
  @blog.settings.title = 'My Space'
39
43
  @blog.settings(:theme).background_color = 'blue'
@@ -41,14 +45,18 @@ Set settings
41
45
  @blog.save
42
46
  ```
43
47
 
44
- Get settings
48
+ ### Get settings
49
+
45
50
  ```ruby
46
- @blog.settings(:theme).background_color # returns 'blue'
51
+ @blog.settings(:theme).background_color
52
+ => 'blue'
47
53
 
48
- @blog.settings(:post).pagination # returns nil if not set
54
+ # returns nil if not set
55
+ @blog.settings(:post).pagination
56
+ => nil
49
57
  ```
50
58
 
51
- ## Default Values
59
+ ## Defining Default Values
52
60
 
53
61
  ```ruby
54
62
  class Blog < ActiveRecord::Base
@@ -60,50 +68,71 @@ class Blog < ActiveRecord::Base
60
68
  end
61
69
  end
62
70
  ```
71
+
63
72
  OR
73
+
64
74
  ```ruby
65
75
  class Blog < ActiveRecord::Base
66
76
  has_settings_on :column do |s|
67
- s.key :theme, defaults:{ background_color: 'red', text_size: 50 }
77
+ s.key :theme, defaults: { background_color: 'red', text_size: 50 }
68
78
  s.attr :title, default: 'My Space'
69
79
  end
70
80
  end
71
81
  ```
72
82
 
73
83
  You can get these defaults by:
84
+
74
85
  ```ruby
75
- @blog.settings(:theme).background_color # 'red'
76
- @blog.settings(:theme).text_size # 50
77
- @blog.settings.title # 'My Space'
86
+ @blog.settings(:theme).background_color
87
+ => 'red'
88
+
89
+ @blog.settings(:theme).text_size
90
+ => 50
91
+
92
+ @blog.settings.title
93
+ => 'My Space'
78
94
  ```
79
95
 
80
96
  ## Nested Keys
81
- Settings on Rails supports nested keys
97
+
98
+ Settings on Rails supports nested keys by chaining calls to the `settings` method:
99
+
82
100
  ```ruby
83
101
  # Set
84
102
  @blog.settings(:theme).settings(:homepage).background_color = 'white'
103
+
85
104
  # Get
86
- @blog.settings(:theme).settings(:homepage).background_color # 'white'
105
+ @blog.settings(:theme).settings(:homepage).background_color
106
+ => 'white'
87
107
  ```
88
108
 
89
- # Multiple Keys
90
- You can also define you nested keys in following ways, it's equal to nested keys
109
+ ## Multiple Keys
110
+
111
+ You can also define multiple keys in the following way, this is equivalent to nested keys:
112
+
91
113
  ```ruby
92
114
  # Set
93
115
  @blog.settings(:theme, :homepage).background_color = 'white'
116
+
94
117
  # Get
95
- @blog.settings(:theme, :homepage).background_color # 'white'
118
+ @blog.settings(:theme, :homepage).background_color
119
+ => 'white'
96
120
  ```
97
121
 
98
122
 
99
123
  ## Method Name Customization
100
- You can customize the name of the settings method
124
+
125
+ You can customize the name of the `settings` method:
126
+
101
127
  ```ruby
102
128
  class Blog < ActiveRecord::Base
103
129
  has_settings_on :settings_column, method: :preferences
104
130
  end
131
+ ```
105
132
 
106
- # Then you can do
133
+ Which allows you to do:
134
+
135
+ ```ruby
107
136
  @blog.preferences(:theme).background_color
108
137
  ```
109
138
 
@@ -41,6 +41,10 @@ module SettingsOnRails
41
41
  current_node
42
42
  end
43
43
 
44
+ def inspect
45
+ "#<#{self.class.name}:#{self.object_id}, node: #{_current_node}>"
46
+ end
47
+
44
48
  private
45
49
 
46
50
  def _settings(*keys)
@@ -1,3 +1,3 @@
1
1
  module SettingsOnRails
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settings_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ALLEN WANG QIANG
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -125,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.5
128
+ rubygems_version: 2.4.5.1
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Model specific Hash Preferences/Settings for Rails.
132
132
  test_files: []
133
- has_rdoc: