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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4aadf4bccff98b7ced078c972968db8547fd11a8
4
- data.tar.gz: 15f349ef414bea02b78b773332a4f7551741cb53
3
+ metadata.gz: d1d36e3bb824530912c342545f36b9f6c682c69a
4
+ data.tar.gz: 11d92eb4ed0036cb21b86a7ffe6306e80322b1a1
5
5
  SHA512:
6
- metadata.gz: 73e0a0cf95d25aa59f6d32816448a91c79e9f2c4b0e6f4ebad44ede858b8932e793bc7be565873ca34ad8b28a94a84b30820827ee1c5c2ab4df96f6081a43d73
7
- data.tar.gz: 0031c12cc60702bef5c440d993afd2b3513436c979063f63c20768138798fbde19f8ae4070c1511d8df2d982b448c4ff11034fdb81188dad3ad66cec2f17e716
6
+ metadata.gz: 3ef8cb3ce3dca277ebb5c4a96dc00c0d87341e145d1842c4ea5f13c809033e1a2c18ab84b0038b1c2d4460bd67ccc3352e1f60aa8054091c692b733202aacea1
7
+ data.tar.gz: ed7197e9ea48bafab3fbc4b6dbe648f194346470815691a136edc270c0d31c08b649f23937e8dbc73a59c02905667666e0ca508431d50df5181e692df11250dd
@@ -1,9 +1,13 @@
1
1
  module Settingson::Base
2
+
2
3
  extend ActiveSupport::Concern
3
4
 
4
5
  module ClassMethods
5
- def hello
6
- 'hello'
6
+
7
+ def method_missing(string, *args)
8
+ ::Settingson::Store.new(self, string, *args)
7
9
  end
10
+
8
11
  end
12
+
9
13
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "0.0.15"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/settingson.rb CHANGED
@@ -3,5 +3,6 @@ require "settingson/version"
3
3
  module Settingson
4
4
  if defined?(Rails)
5
5
  require 'settingson/engine'
6
+ require 'settingson/store'
6
7
  end
7
8
  end
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.15
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-02 00:00:00.000000000 Z
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