settingson 0.1.0 → 0.1.1

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: d1d36e3bb824530912c342545f36b9f6c682c69a
4
- data.tar.gz: 11d92eb4ed0036cb21b86a7ffe6306e80322b1a1
3
+ metadata.gz: c45e0fe97f344f3bb38ee9632a70f2ae72ea2c79
4
+ data.tar.gz: b0ff834e5623d24da90c18b6eae0b01fc9ef3f56
5
5
  SHA512:
6
- metadata.gz: 3ef8cb3ce3dca277ebb5c4a96dc00c0d87341e145d1842c4ea5f13c809033e1a2c18ab84b0038b1c2d4460bd67ccc3352e1f60aa8054091c692b733202aacea1
7
- data.tar.gz: ed7197e9ea48bafab3fbc4b6dbe648f194346470815691a136edc270c0d31c08b649f23937e8dbc73a59c02905667666e0ca508431d50df5181e692df11250dd
6
+ metadata.gz: 812fba267cf8f56b5ed924a64f649808860a05c194e7ba6d1d3b43ca9b460cc0f3a5b7b878c05c295d460521f9dff15b319aea9260395ee1fc6190a84299e3ca
7
+ data.tar.gz: 2adb0f77056e1e2fb0ba4b8a97fdf4817f2e7d2d2cf0e600f4925ccb7fedf3fecf13c6128ad0b4b410a45c596a586cc1d55c002eee7c32f03a17331f0a331a8e
data/README.md CHANGED
@@ -37,6 +37,37 @@ rake db:migrate
37
37
  ```
38
38
  as the generator will have created a migration file (if your ORM supports them).
39
39
 
40
+ ## Example
41
+
42
+ ```console
43
+ rails g settingson Settings
44
+ rake db:migrate
45
+ ```
46
+
47
+ In rails console:
48
+ ```ruby
49
+ 2.1.1 :006 > Settings.hello.hello3.hello2
50
+ Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1
51
+ Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1
52
+ Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1
53
+ => #<Settingson::Store:0x000001016aee68 @klass=Settings(id: integer, name: string, value: text, created_at: datetime, updated_at: datetime), @name="hello.hello3.hello2", @value=#<Settingson::Store:0x000001016aee68 ...>>
54
+
55
+ 2.1.1 :007 > Settings.hello.hello3.hello2 = 1
56
+ Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1
57
+ Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1
58
+ Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1
59
+ (0.1ms) begin transaction
60
+ SQL (5.2ms) INSERT INTO "settings" ("created_at", "name", "updated_at", "value") VALUES (?, ?, ?, ?) [["created_at", Sat, 03 May 2014 09:45:25 UTC +00:00], ["name", "hello.hello3.hello2"], ["updated_at", Sat, 03 May 2014 09:45:25 UTC +00:00], ["value", "--- 1\n...\n"]]
61
+ (2.4ms) commit transaction
62
+ => 1
63
+
64
+ 2.1.1 :008 > Settings.hello.hello3.hello2
65
+ Settings Load (0.3ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1
66
+ Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1
67
+ Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1
68
+ => 1
69
+ ```
70
+
40
71
  ## Contributing
41
72
 
42
73
  1. Fork it ( https://github.com/daanforever/settingson/fork )
@@ -5,7 +5,11 @@ module Settingson::Base
5
5
  module ClassMethods
6
6
 
7
7
  def method_missing(string, *args)
8
- ::Settingson::Store.new(self, string, *args)
8
+ if result = find_by(name: string)
9
+ YAML.load result.value
10
+ else
11
+ ::Settingson::Store.new(self, string, *args)
12
+ end
9
13
  end
10
14
 
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dan