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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fc78fcfbb6cf5dd08387e17e4511592c54f8a6b
4
- data.tar.gz: 722a0ed7078a8d226357be181e59c68e9867c4c8
3
+ metadata.gz: 95128b9250dc2c4165be8b78f081e41f80ff382c
4
+ data.tar.gz: 35988646918c5965dca2fd9f9e915a790f8405df
5
5
  SHA512:
6
- metadata.gz: d0dd05c922c84b7c926de25f23415cd77a97255ee8a93ee5b036bbcbbd6c9da0c8a6418e1edfe4eb283f416861c8c82747a187bb046edd854ed25ad614c31a67
7
- data.tar.gz: cb3b32a60cc0216850570983ce898fb8ed4dee48d3611b49f01251bf9ab21f73fe480e3b68d8581f6baa2705d85862777e8d8b1639a88fa2267cde83f9e61447
6
+ metadata.gz: 7bb1b7ef581aecdd6d0e9f6b26fcaac3bc7e5609d3e2a35ec691cec4fede7ff83cec5789639dc02bae3534404868bbaddd8605a997cb14076523132020df4127
7
+ data.tar.gz: ed6f4cc686204e60e32f677867125cfb51b84d702081731e63f1484dc0f7765fee7f60909665e112e829b9d96763b6a6e73c88cf42bbb431a2b485f6ae94465a
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - dan