configurable_engine 0.4.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +27 -0
- data/README.md +42 -8
- data/app/models/configurable.rb +45 -11
- data/app/views/admin/configurables/show.html.erb +29 -22
- data/lib/configurable_engine/version.rb +2 -2
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 70df04df8400f52621c669ff912d9b648b4cac4a1107b3e5e0e102f2aeaabe51
|
4
|
+
data.tar.gz: 3a32bee140f6e905ce74f5079ed034611055f46727645f8dbe39ff22e7e4d9a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fe20672f98d7b4166c224d73bf1d10675a71418d3a32dcc7e952cba3a0dffa62c4e03635877fa097c21e592a970f8d952c8602c6fc7db91e39857b1710b0339
|
7
|
+
data.tar.gz: c77bb417b1bf4cbe6f4d23b9875049fedd05fcbad8efb6db25f87f698ec7c70fa97eda580dd11da0e4b842caaf8d40fab1e76cd570fb6fcc85af9bb8a438f7f8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
### v1.0.0 - August 20, 2020
|
2
|
+
**features**
|
3
|
+
Official rails 5.2 support
|
4
|
+
|
5
|
+
**breaking changes**
|
6
|
+
No further support for rails < 5.2
|
7
|
+
|
8
|
+
### v0.5.0 - August 3, 2018
|
9
|
+
**features**
|
10
|
+
Official rails 4.2 support (Thanks @ento)
|
11
|
+
|
12
|
+
**breaking changes**
|
13
|
+
No further support for rails < 4.2, and non-mri rubies. Happy to accept those back as PRs!
|
14
|
+
|
15
|
+
|
16
|
+
### v0.4.8 - March 4, 2015
|
17
|
+
**bug fix**
|
18
|
+
Cacheing was just totally broken. Whoops! (thanks, @antoshalee)
|
19
|
+
|
20
|
+
### v0.4.7 - November 4, 2014
|
21
|
+
**bug fix**
|
22
|
+
Configurable broke for users using cacheing.
|
23
|
+
|
24
|
+
### v0.4.6 - October 28, 2014
|
25
|
+
**cleanup**
|
26
|
+
When using Configurable with cache, destroying a configurable instance erases it from cache
|
27
|
+
|
1
28
|
### v0.4.5 - October 13, 2014
|
2
29
|
**bug fixes**
|
3
30
|
Configurable can store false values when the default is true (https://github.com/paulca/configurable_engine/pull/24, thanks @lilliealbert)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Configurable [![Build Status](https://travis-ci.org/paulca/configurable_engine.png?branch=master)](https://travis-ci.org/paulca/configurable_engine)
|
2
2
|
|
3
|
-
A Rails
|
3
|
+
A Rails 4 configuration engine. An update to [Behavior](http://github.com/paulca/behavior) for Rails 4.
|
4
4
|
|
5
5
|
## How it works ##
|
6
6
|
|
@@ -10,7 +10,7 @@ If you or your app users need to change these variables, Configurable stores new
|
|
10
10
|
|
11
11
|
## Installation ##
|
12
12
|
|
13
|
-
Configurable is available as a Ruby gem. Simply add it to your Rails
|
13
|
+
Configurable is available as a Ruby gem. Simply add it to your Rails 4 app's `Gemfile`:
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
gem 'configurable_engine'
|
@@ -24,9 +24,9 @@ $ rails generate configurable_engine:install
|
|
24
24
|
|
25
25
|
## Usage ##
|
26
26
|
|
27
|
-
There are two parts to how configurable_engine works. First of all there is a config file, config/configurable.yml
|
27
|
+
There are two parts to how configurable_engine works. First of all there is a config file, `config/configurable.yml`. This file controls the variables that are allowed to be set in the app.
|
28
28
|
|
29
|
-
For example, if you wanted to have access to a config variable
|
29
|
+
For example, if you wanted to have access to a config variable `site_title`, put this in `configurable.yml`:
|
30
30
|
|
31
31
|
```yaml
|
32
32
|
site_title:
|
@@ -100,16 +100,50 @@ Price:
|
|
100
100
|
type: decimal # coerces the value to a decimal
|
101
101
|
```
|
102
102
|
|
103
|
-
##
|
103
|
+
## Caching ##
|
104
104
|
|
105
105
|
If you want to use rails caching of Configurable updates, simply set
|
106
106
|
|
107
|
-
|
108
107
|
```ruby
|
109
108
|
config.use_cache = true
|
110
109
|
```
|
110
|
+
|
111
111
|
in your `config/application.rb` (or `config/production.rb`)
|
112
112
|
|
113
|
+
## Styling the interface ##
|
114
|
+
|
115
|
+
To style the web interface you are advised to use Sass. Here's an example scss file that will make the interface bootstrap-3 ready:
|
116
|
+
|
117
|
+
```
|
118
|
+
@import 'bootstrap';
|
119
|
+
|
120
|
+
.configurable-container {
|
121
|
+
@extend .col-md-6;
|
122
|
+
|
123
|
+
.configurable-options {
|
124
|
+
form {
|
125
|
+
@extend .form-horizontal;
|
126
|
+
|
127
|
+
.configurable {
|
128
|
+
@extend .col-md-12;
|
129
|
+
@extend .form-group;
|
130
|
+
|
131
|
+
textarea, input[type=text], input[type=password] {
|
132
|
+
@extend .form-control;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
input[type=submit] {
|
137
|
+
@extend .btn;
|
138
|
+
@extend .btn-primary;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
Just save this into your rails assets and you're ready to go.
|
146
|
+
|
113
147
|
## Running the Tests ##
|
114
148
|
|
115
149
|
The tests for this rails engine are in the `spec` and `features` directories. They use the dummy rails app in `spec/dummy`
|
@@ -117,7 +151,8 @@ The tests for this rails engine are in the `spec` and `features` directories. T
|
|
117
151
|
From the top level run:
|
118
152
|
|
119
153
|
```bash
|
120
|
-
$ bundle exec rake app:db:schema:load
|
154
|
+
$ bundle exec rake app:db:schema:load
|
155
|
+
$ bundle exec rake app:db:test:prepare
|
121
156
|
$ bundle exec rake
|
122
157
|
```
|
123
158
|
|
@@ -129,4 +164,3 @@ All contributions are welcome. Just fork the code, ensure your changes include a
|
|
129
164
|
|
130
165
|
Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
|
131
166
|
further details.
|
132
|
-
|
data/app/models/configurable.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class Configurable < ActiveRecord::Base
|
2
|
+
serialize :value
|
2
3
|
|
3
|
-
after_save
|
4
|
+
after_save :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
|
5
|
+
after_destroy :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
|
4
6
|
|
5
7
|
validates_presence_of :name
|
6
8
|
validates_uniqueness_of :name
|
@@ -29,20 +31,44 @@ class Configurable < ActiveRecord::Base
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
def self.cache_key(key)
|
35
|
+
"configurable_engine:#{key}"
|
36
|
+
end
|
37
|
+
|
32
38
|
def self.[](key)
|
33
39
|
return parse_value key, defaults[key][:default] unless table_exists?
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
find_by_name(key)
|
41
|
+
value, found = [false, false]
|
42
|
+
database_finder = -> do
|
43
|
+
config = find_by_name(key)
|
44
|
+
found = !!config
|
45
|
+
value = config.try(:value)
|
41
46
|
end
|
42
47
|
|
43
|
-
return parse_value key, defaults[key][:default] unless config
|
44
48
|
|
45
|
-
config.
|
49
|
+
if ConfigurableEngine::Engine.config.use_cache
|
50
|
+
found = Rails.cache.exist?(cache_key(key))
|
51
|
+
if found
|
52
|
+
value = Rails.cache.fetch(cache_key(key))
|
53
|
+
else
|
54
|
+
database_finder.call
|
55
|
+
if found
|
56
|
+
Rails.cache.write cache_key(key), value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
database_finder.call
|
61
|
+
end
|
62
|
+
|
63
|
+
if found
|
64
|
+
value
|
65
|
+
else
|
66
|
+
parse_value(key, defaults[key][:default]).tap do |val|
|
67
|
+
if ConfigurableEngine::Engine.config.use_cache
|
68
|
+
Rails.cache.write cache_key(key), val
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
46
72
|
end
|
47
73
|
|
48
74
|
def value
|
@@ -55,7 +81,7 @@ class Configurable < ActiveRecord::Base
|
|
55
81
|
[true, 1, "1", "t", "true"].include?(value)
|
56
82
|
when 'decimal'
|
57
83
|
value ||= 0
|
58
|
-
BigDecimal
|
84
|
+
BigDecimal(value.to_s)
|
59
85
|
when 'integer'
|
60
86
|
value.to_i
|
61
87
|
when 'list'
|
@@ -65,6 +91,12 @@ class Configurable < ActiveRecord::Base
|
|
65
91
|
else
|
66
92
|
value.split("\n").collect { |v| v =~ /,/ ? v.split(',') : v }
|
67
93
|
end
|
94
|
+
when 'date'
|
95
|
+
if value.is_a? Date
|
96
|
+
value
|
97
|
+
else
|
98
|
+
Date.parse(value) if value.present?
|
99
|
+
end
|
68
100
|
else
|
69
101
|
value
|
70
102
|
end
|
@@ -111,6 +143,8 @@ class Configurable < ActiveRecord::Base
|
|
111
143
|
Integer(value) rescue false
|
112
144
|
when 'list'
|
113
145
|
value.is_a?(Array)
|
146
|
+
when 'date'
|
147
|
+
value.is_a?(Date)
|
114
148
|
else
|
115
149
|
true
|
116
150
|
end
|
@@ -122,6 +156,6 @@ class Configurable < ActiveRecord::Base
|
|
122
156
|
end
|
123
157
|
|
124
158
|
def invalidate_cache
|
125
|
-
Rails.cache.delete(
|
159
|
+
Rails.cache.delete(Configurable.cache_key self.name)
|
126
160
|
end
|
127
161
|
end
|
@@ -1,24 +1,31 @@
|
|
1
|
-
<
|
1
|
+
<div class='configurable-container'>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
<div class="header">
|
4
|
+
<h2>Config</h2>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<div class="configurable-options">
|
8
|
+
<%= form_tag(admin_configurable_path, :method => :put) do -%>
|
9
|
+
<%- @keys.each do |key| -%>
|
10
|
+
<%- options = Configurable.defaults[key] -%>
|
11
|
+
<div class="configurable">
|
12
|
+
<%= label_tag key, options[:name] %>
|
13
|
+
<%- if options[:type] == 'boolean' %>
|
14
|
+
<%= hidden_field_tag key, "0" %>
|
15
|
+
<%= check_box_tag key, "1", Configurable.send(key) %>
|
16
|
+
<%- elsif options[:type] == 'password' -%>
|
17
|
+
<%= password_field_tag key, Configurable.send(key) %>
|
18
|
+
<%- elsif options[:type] == 'text' -%>
|
19
|
+
<%= text_area_tag key, Configurable.send(key) %>
|
20
|
+
<%- elsif options[:type] == 'list' -%>
|
21
|
+
<%= text_area_tag key, Configurable.serialized_value(key) -%>
|
22
|
+
<%- else -%>
|
23
|
+
<%= text_field_tag key, Configurable.send(key) %>
|
24
|
+
<%- end -%>
|
25
|
+
</div>
|
19
26
|
<%- end -%>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
|
28
|
+
<%= submit_tag 'Save' %>
|
29
|
+
<%- end -%>
|
30
|
+
</div>
|
31
|
+
</div>
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ConfigurableEngine
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurable_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Campbell
|
8
8
|
- Michael Glass
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -17,17 +17,17 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 5.2.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
description: 'Configurable is a Rails
|
29
|
-
|
30
|
-
|
27
|
+
version: 5.2.0
|
28
|
+
description: 'Configurable is a Rails 4 engine that allows you to set up config variables
|
29
|
+
in a config file, specifying default values for all environmentspec. These variables
|
30
|
+
can then be set on a per-app basis using a user facing configuration screen. '
|
31
31
|
email: paul@rslw.com
|
32
32
|
executables: []
|
33
33
|
extensions: []
|
@@ -53,7 +53,7 @@ homepage: http://github.com/paulca/configurable_engine
|
|
53
53
|
licenses:
|
54
54
|
- MIT
|
55
55
|
metadata: {}
|
56
|
-
post_install_message:
|
56
|
+
post_install_message:
|
57
57
|
rdoc_options: []
|
58
58
|
require_paths:
|
59
59
|
- lib
|
@@ -68,9 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
signing_key:
|
71
|
+
rubygems_version: 3.0.3
|
72
|
+
signing_key:
|
74
73
|
specification_version: 4
|
75
|
-
summary: Database-backed configuration for Rails
|
74
|
+
summary: Database-backed configuration for Rails 4, with defaults from config file.
|
76
75
|
test_files: []
|