settingson 1.0.0 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/settingson/store.rb +36 -0
- data/lib/settingson/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95128b9250dc2c4165be8b78f081e41f80ff382c
|
4
|
+
data.tar.gz: 35988646918c5965dca2fd9f9e915a790f8405df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bb1b7ef581aecdd6d0e9f6b26fcaac3bc7e5609d3e2a35ec691cec4fede7ff83cec5789639dc02bae3534404868bbaddd8605a997cb14076523132020df4127
|
7
|
+
data.tar.gz: ed6f4cc686204e60e32f677867125cfb51b84d702081731e63f1484dc0f7765fee7f60909665e112e829b9d96763b6a6e73c88cf42bbb431a2b485f6ae94465a
|
data/lib/settingson/store.rb
CHANGED
@@ -19,6 +19,42 @@ class Settingson::Store
|
|
19
19
|
true
|
20
20
|
end
|
21
21
|
|
22
|
+
def [](*args)
|
23
|
+
return nil if args.nil?
|
24
|
+
if args.count == 1
|
25
|
+
result = @klass.find_by(name: "#{@name}.#{args.first}").try(:value)
|
26
|
+
result.nil? ? nil : YAML.load(result)
|
27
|
+
else
|
28
|
+
args.map do |subname|
|
29
|
+
result = @klass.find_by(name: "#{@name}.#{subname}").try(:value)
|
30
|
+
result.nil? ? nil : YAML.load(result)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(*args)
|
36
|
+
return nil if args.nil?
|
37
|
+
if args.count == 2
|
38
|
+
if record = @klass.find_by(name: "#{@name}.#{args.first}")
|
39
|
+
record.update(value: args.last.to_yaml)
|
40
|
+
else
|
41
|
+
@klass.create(name: "#{@name}.#{args.first}", value: args.last.to_yaml)
|
42
|
+
end
|
43
|
+
args.last
|
44
|
+
elsif args.count > 2
|
45
|
+
values = args.pop
|
46
|
+
args.map do |subname|
|
47
|
+
value = values.shift
|
48
|
+
if record = @klass.find_by(name: "#{@name}.#{subname}")
|
49
|
+
record.update(value: value.to_yaml)
|
50
|
+
else
|
51
|
+
@klass.create(name: "#{@name}.#{subname}", value: value.to_yaml)
|
52
|
+
end
|
53
|
+
value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
22
58
|
def method_missing(string, *args)
|
23
59
|
@value = parse(string, args.first)
|
24
60
|
end
|
data/lib/settingson/version.rb
CHANGED