configurable_engine 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +63 -46
- data/app/models/configurable.rb +1 -1
- data/lib/configurable_engine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 990bdf66a3b906927e53869aa049a82638b13791
|
4
|
+
data.tar.gz: 1107460d5c031cc5b143b950966cb8548b5a5529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 204972e4fc0157f654f0900e3156dba911c11d5fd45878d2c3ec3d6cc115c25ac4b8e4d131d10b8d0a43cd000d0aeec431cb29dc9f0faf90199be5fbba50b6d4
|
7
|
+
data.tar.gz: 9422ce1965bd055dc95fc0597f7945433011548172b73b144fdd39ab38aa90ff2d7f66766725f107134d6ecc20038059ad3210af49b257dd0391e4ea9c0c5153
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,11 +12,15 @@ If you or your app users need to change these variables, Configurable stores new
|
|
12
12
|
|
13
13
|
Configurable is available as a Ruby gem. Simply add it to your Rails 3 app's `Gemfile`:
|
14
14
|
|
15
|
-
|
15
|
+
```ruby
|
16
|
+
gem 'configurable_engine'
|
17
|
+
```
|
16
18
|
|
17
19
|
Then run the `configurable_engine:install` generator:
|
18
20
|
|
19
|
-
|
21
|
+
```bash
|
22
|
+
$ rails generate configurable_engine:install
|
23
|
+
```
|
20
24
|
|
21
25
|
## Usage ##
|
22
26
|
|
@@ -24,68 +28,79 @@ There are two parts to how configurable_engine works. First of all there is a co
|
|
24
28
|
|
25
29
|
For example, if you wanted to have access to a config variable "site_title", put this in configurable.yml:
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
```yaml
|
32
|
+
site_title:
|
33
|
+
name: Site Title
|
34
|
+
default: My Site
|
35
|
+
# type: String is the default
|
36
|
+
```
|
31
37
|
Now, within your app, you can access `Configurable[:site_title]` (or `Configurable.site_title` if you prefer).
|
32
38
|
|
33
39
|
Since Configurable is an ActiveRecord model, if you want to update the config, create a Configurable record in the database:
|
34
40
|
|
35
|
-
|
36
|
-
|
41
|
+
```ruby
|
42
|
+
Configurable.create!(:name => 'site_title', :value => 'My New Site')
|
43
|
+
```
|
44
|
+
You can set the `type` attribute to `boolean`, `decimal`,`integer`, or `list` and it will treat those fields as those types. Lists are comma and/or newline delimeted arrays of strings.
|
45
|
+
|
37
46
|
## Web Interface ##
|
38
47
|
|
39
48
|
Configurable comes with a web interface that is available to your app straight away at `http://localhost:3000/admin/configurable`.
|
40
49
|
|
41
50
|
If you want to add a layout, or protect the configurable controller, create `app/controllers/admin/configurables_controller.rb` as such:
|
42
51
|
|
43
|
-
|
52
|
+
```bash
|
53
|
+
$ bundle exec rails generate controller admin/configurables
|
54
|
+
```
|
44
55
|
|
45
56
|
and include `ConfigurableEngine::ConfigurablesController`, eg.
|
46
57
|
|
47
|
-
|
48
|
-
|
49
|
-
|
58
|
+
```ruby
|
59
|
+
class Admin::ConfigurablesController < ApplicationController
|
60
|
+
# include the engine controller actions
|
61
|
+
include ConfigurableEngine::ConfigurablesController
|
50
62
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
63
|
+
# add your own filter(s) / layout
|
64
|
+
before_filter :protect_my_code
|
65
|
+
layout 'admin'
|
66
|
+
end
|
67
|
+
```
|
55
68
|
|
56
69
|
If you want to control how the fields in the admin interface appear, you can add additional params in your configurable.yml file:
|
57
70
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
```yaml
|
72
|
+
site_title:
|
73
|
+
name: Name of Your Site # sets the edit label
|
74
|
+
default: My Site # sets the default value
|
75
|
+
type: string # uses input type="text"
|
76
|
+
site_description:
|
77
|
+
name: Describe Your Site # sets the edit label
|
78
|
+
default: My Site # sets the default value
|
79
|
+
type: text # uses textarea
|
80
|
+
secret:
|
81
|
+
name: A Secret Passphrase # sets the edit label
|
82
|
+
default: passpass # sets the default value
|
83
|
+
type: password # uses input type="password"
|
84
|
+
|
85
|
+
Value:
|
86
|
+
name: A number # sets the edit label
|
87
|
+
default: 10 # sets the default value
|
88
|
+
type: integer # coerces the value to an integer
|
89
|
+
|
90
|
+
Price:
|
91
|
+
name: A price # sets the edit label
|
92
|
+
default: "10.00" # sets the default value
|
93
|
+
type: decimal # coerces the value to a decimal
|
94
|
+
```
|
95
|
+
|
83
96
|
## Cacheing ##
|
84
97
|
|
85
98
|
If you want to use rails caching of Configurable updates, simply set
|
86
99
|
|
87
|
-
|
88
|
-
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
config.use_cache = true
|
103
|
+
```
|
89
104
|
in your `config/application.rb` (or `config/production.rb`)
|
90
105
|
|
91
106
|
## Running the Tests ##
|
@@ -94,9 +109,11 @@ The tests for this rails engine are in the `spec` and `features` directories. T
|
|
94
109
|
|
95
110
|
From the top level run:
|
96
111
|
|
97
|
-
|
98
|
-
|
99
|
-
|
112
|
+
```bash
|
113
|
+
$ bundle exec rake app:db:schema:load app:db:test:prepare
|
114
|
+
$ bundle exec rake
|
115
|
+
```
|
116
|
+
|
100
117
|
## Contributing ##
|
101
118
|
|
102
119
|
All contributions are welcome. Just fork the code, ensure your changes include a test, ensure all the current tests pass and send a pull request.
|
data/app/models/configurable.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurable_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Campbell
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.2.
|
71
|
+
rubygems_version: 2.2.2
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: Database-backed configuration for Rails 3, with defaults from config file.
|