settingson 0.0.15 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/settingson/base.rb +6 -2
- data/lib/settingson/store.rb +47 -0
- data/lib/settingson/version.rb +1 -1
- data/lib/settingson.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1d36e3bb824530912c342545f36b9f6c682c69a
|
4
|
+
data.tar.gz: 11d92eb4ed0036cb21b86a7ffe6306e80322b1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef8cb3ce3dca277ebb5c4a96dc00c0d87341e145d1842c4ea5f13c809033e1a2c18ab84b0038b1c2d4460bd67ccc3352e1f60aa8054091c692b733202aacea1
|
7
|
+
data.tar.gz: ed7197e9ea48bafab3fbc4b6dbe648f194346470815691a136edc270c0d31c08b649f23937e8dbc73a59c02905667666e0ca508431d50df5181e692df11250dd
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Settingson::Store
|
2
|
+
|
3
|
+
attr_accessor :name, :value
|
4
|
+
|
5
|
+
def initialize(klass, string, *args)
|
6
|
+
@klass = klass
|
7
|
+
@value = parse(string, args.first)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
@value
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_ary
|
15
|
+
[ @value ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def nil?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(string, *args)
|
23
|
+
@value = parse(string, args.first)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def parse(string, value)
|
28
|
+
case string.to_s
|
29
|
+
when /(.+)=/
|
30
|
+
@name = @name.nil? ? $1 : @name + ".#{$1}"
|
31
|
+
if record = @klass.find_by(name: @name)
|
32
|
+
record.update(value: value.to_yaml)
|
33
|
+
value
|
34
|
+
else
|
35
|
+
@klass.create(name: @name, value: value.to_yaml)
|
36
|
+
value
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@name = @name.nil? ? string.to_s : @name + ".#{string.to_s}"
|
40
|
+
if result = @klass.find_by(name: @name)
|
41
|
+
YAML.load result.value
|
42
|
+
else
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/settingson/version.rb
CHANGED
data/lib/settingson.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: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/generators/settingson/settingson_generator.rb
|
55
55
|
- lib/settingson.rb
|
56
56
|
- lib/settingson/engine.rb
|
57
|
+
- lib/settingson/store.rb
|
57
58
|
- lib/settingson/version.rb
|
58
59
|
- settingson.gemspec
|
59
60
|
homepage: https://github.com/daanforever/settingson
|