settingson 1.2.22 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/app/models/concerns/settingson/base.rb +8 -12
- data/lib/settingson/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa6d03e8b75983a07d5e6785a4e4568ee5ed263
|
4
|
+
data.tar.gz: ef2d696f0832dd9cae9b44b94d335057a9f8c9e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 941079284edbe34349d08f5623413bdffcf676cbabcfbd3449bc625b57a7cf8c8b5b3fd611caec6f21a9855321ebc702c68651db4161d6856d75da6823df19ad
|
7
|
+
data.tar.gz: 00c50d207845a378789147fc5080475738f5c810d7c5b158c830039df6af4c846954f090cd9ed2727ac766e89cd4b0eab082ae6d434bee86946d2185f753f99c
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Settings.array # => [1, 2, 3, 4, 5]
|
|
28
28
|
# Array of hashes
|
29
29
|
Settings.array_of.hashes = [ { hello: :world}, {'glad' => :to}, {see: 'you'} ]
|
30
30
|
Settings.array_of.hashes # => [{:hello=>:world}, {"glad"=>:to}, {:see=>"you"}]
|
31
|
-
|
31
|
+
|
32
32
|
# Boolean
|
33
33
|
Settings.item # => false
|
34
34
|
Settings.item = :hello
|
@@ -36,13 +36,15 @@ Settings.item # => true
|
|
36
36
|
|
37
37
|
# ActiveRecord
|
38
38
|
Settings.item! # => <Settings id: 1, key: "item", value: :hello, created_at: "...", updated_at: "...">
|
39
|
+
```
|
39
40
|
|
40
41
|
### Using with [Simple Form](https://github.com/plataformatec/simple_form) and [Haml](https://github.com/haml/haml)
|
41
42
|
in view:
|
42
43
|
```ruby
|
43
|
-
= simple_form_for
|
44
|
-
= f.
|
45
|
-
= f.input :port
|
44
|
+
= simple_form_for(Settings, url: settings_path) do |f|
|
45
|
+
= f.error_notification
|
46
|
+
= f.input :'host.port'
|
47
|
+
= f.button :submit
|
46
48
|
```
|
47
49
|
|
48
50
|
## Installation
|
@@ -4,10 +4,7 @@ module Settingson::Base
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
attr_accessor :settingson
|
7
|
-
|
8
|
-
after_find do |setting|
|
9
|
-
setting.value = YAML.load(setting.value)
|
10
|
-
end
|
7
|
+
serialize :value
|
11
8
|
end
|
12
9
|
|
13
10
|
def to_s
|
@@ -30,9 +27,9 @@ module Settingson::Base
|
|
30
27
|
if record = self.class.find_by(key: @settingson) and args.first.nil?
|
31
28
|
record.destroy
|
32
29
|
elsif record
|
33
|
-
record.update(value: args.first
|
30
|
+
record.update(value: args.first)
|
34
31
|
else
|
35
|
-
self.class.create(key: @settingson, value: args.first
|
32
|
+
self.class.create(key: @settingson, value: args.first)
|
36
33
|
end
|
37
34
|
when /(.+)\?$/ # returns boolean
|
38
35
|
@settingson = "#{@settingson}.#{$1}"
|
@@ -47,7 +44,7 @@ module Settingson::Base
|
|
47
44
|
else
|
48
45
|
@settingson += ".#{symbol.to_s}"
|
49
46
|
end
|
50
|
-
|
47
|
+
|
51
48
|
if record = self.class.find_by(key: @settingson)
|
52
49
|
record.value
|
53
50
|
else
|
@@ -71,19 +68,18 @@ module Settingson::Base
|
|
71
68
|
if record = find_by(key: @settingson) and args.first.nil?
|
72
69
|
record.destroy
|
73
70
|
elsif record
|
74
|
-
record.update(value: args.first
|
71
|
+
record.update(value: args.first)
|
75
72
|
else
|
76
|
-
create(key: @settingson, value: args.first
|
73
|
+
create(key: @settingson, value: args.first, settingson: @settingson)
|
77
74
|
end
|
78
|
-
|
79
|
-
when /(.+)\?$/ #
|
75
|
+
|
76
|
+
when /(.+)\?$/ #
|
80
77
|
find_by(key: $1).present?
|
81
78
|
when /(.+)\!$/ # returns self or nil
|
82
79
|
find_by(key: $1)
|
83
80
|
else # getter
|
84
81
|
|
85
82
|
if record = find_by(key: symbol.to_s)
|
86
|
-
# YAML.load record.value
|
87
83
|
record.value
|
88
84
|
else
|
89
85
|
new(settingson: symbol.to_s)
|
data/lib/settingson/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settingson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
213
|
version: '0'
|
214
214
|
requirements: []
|
215
215
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.4.
|
216
|
+
rubygems_version: 2.4.6
|
217
217
|
signing_key:
|
218
218
|
specification_version: 4
|
219
219
|
summary: Settings management for Ruby on Rails 4 applications (ActiveRecord)
|