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 +4 -4
- data/README.md +31 -0
- data/app/models/concerns/settingson/base.rb +5 -1
- 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: c45e0fe97f344f3bb38ee9632a70f2ae72ea2c79
|
4
|
+
data.tar.gz: b0ff834e5623d24da90c18b6eae0b01fc9ef3f56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/settingson/version.rb
CHANGED