configurable_engine 0.4.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6818d2942967d86bf45d1e1c65cb13308baa2895
4
- data.tar.gz: d8980df6e210571c7ed06b799ac4eb61b36986be
2
+ SHA256:
3
+ metadata.gz: 541d4ad357b6438a52c6b017f67cd7d83a3f84069671c69952a55babc64afec9
4
+ data.tar.gz: 99acc47f826dedf5d0b6a6e35020864028e58977c8a6f072ac9a4152b62e29df
5
5
  SHA512:
6
- metadata.gz: 671f136a982caff40684be36d236506fd2621eb2eba35d35f16f3b771a5b00eac9f21967ca2a12d1982bc731c83d06a8c7dbef9dcca2ea7b943c58ccf9498c7d
7
- data.tar.gz: 3c5a422c4cc0ef2304f80f9d8cf7cbf8136075079cdecae88c96a4b3a063e7607043f1a31b27fda6c1b1640b478da8d098fc718341bb23f4e9d6f92126c8e4b3
6
+ metadata.gz: df600a1f9d9c6af12d826983027fd05bdd90f0879d0cfea87320fccfe4301df62296c5e05b552c3c75ed9f90059ea630e4dd927808a7a25ab0f0371dbbd75c35
7
+ data.tar.gz: b2e0e897399245a072d060d7e714baf3924a393cde664cd8449ea10c98dacee9e01cbba086d1b12fc4dd9688183f1793d6fbfcef5a4beb9a348632607aa99eaa
@@ -1,3 +1,33 @@
1
+ ### v2.0.0 - August 20, 2020
2
+ **features**
3
+ Configurable_Engine is mountable. This allows folks to use it with a catch-all route
4
+
5
+ **breaking changes**
6
+ Existing users must add `mount ConfigurableEngine::Engine, at: "/admin/configurable"` to their routes.rb. Routing helpers may not work as they used to.
7
+
8
+ ### v1.0.0 - August 20, 2020
9
+ **features**
10
+ Official rails 5.2 support
11
+
12
+ **breaking changes**
13
+ No further support for rails < 5.2
14
+
15
+ ### v0.5.0 - August 3, 2018
16
+ **features**
17
+ Official rails 4.2 support (Thanks @ento)
18
+
19
+ **breaking changes**
20
+ No further support for rails < 4.2, and non-mri rubies. Happy to accept those back as PRs!
21
+
22
+
23
+ ### v0.4.8 - March 4, 2015
24
+ **bug fix**
25
+ Cacheing was just totally broken. Whoops! (thanks, @antoshalee)
26
+
27
+ ### v0.4.7 - November 4, 2014
28
+ **bug fix**
29
+ Configurable broke for users using cacheing.
30
+
1
31
  ### v0.4.6 - October 28, 2014
2
32
  **cleanup**
3
33
  When using Configurable with cache, destroying a configurable instance erases it from cache
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/4 configuration engine. An update to [Behavior](http://github.com/paulca/behavior) for Rails 3 and 4.
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 3 app's `Gemfile`:
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'
@@ -22,11 +22,17 @@ Then run the `configurable_engine:install` generator:
22
22
  $ rails generate configurable_engine:install
23
23
  ```
24
24
 
25
+ this will
26
+ - add config/configurable.yml
27
+ - create a migration for your configurable table
28
+ - mount the UI in your routes (defaulting to admin/configurables)
29
+
30
+
25
31
  ## Usage ##
26
32
 
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.
33
+ 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
34
 
29
- For example, if you wanted to have access to a config variable "site_title", put this in configurable.yml:
35
+ For example, if you wanted to have access to a config variable `site_title`, put this in `configurable.yml`:
30
36
 
31
37
  ```yaml
32
38
  site_title:
@@ -58,7 +64,7 @@ and include `ConfigurableEngine::ConfigurablesController`, eg.
58
64
  ```ruby
59
65
  class Admin::ConfigurablesController < ApplicationController
60
66
  # include the engine controller actions
61
- include ConfigurableEngine::ConfigurablesController
67
+ include ConfigurableEngine::ConfigurablesControllerMethods
62
68
 
63
69
  # add your own filter(s) / layout
64
70
  before_filter :protect_my_code
@@ -100,16 +106,50 @@ Price:
100
106
  type: decimal # coerces the value to a decimal
101
107
  ```
102
108
 
103
- ## Cacheing ##
109
+ ## Caching ##
104
110
 
105
111
  If you want to use rails caching of Configurable updates, simply set
106
112
 
107
-
108
113
  ```ruby
109
114
  config.use_cache = true
110
115
  ```
116
+
111
117
  in your `config/application.rb` (or `config/production.rb`)
112
118
 
119
+ ## Styling the interface ##
120
+
121
+ 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:
122
+
123
+ ```
124
+ @import 'bootstrap';
125
+
126
+ .configurable-container {
127
+ @extend .col-md-6;
128
+
129
+ .configurable-options {
130
+ form {
131
+ @extend .form-horizontal;
132
+
133
+ .configurable {
134
+ @extend .col-md-12;
135
+ @extend .form-group;
136
+
137
+ textarea, input[type=text], input[type=password] {
138
+ @extend .form-control;
139
+ }
140
+ }
141
+
142
+ input[type=submit] {
143
+ @extend .btn;
144
+ @extend .btn-primary;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ Just save this into your rails assets and you're ready to go.
152
+
113
153
  ## Running the Tests ##
114
154
 
115
155
  The tests for this rails engine are in the `spec` and `features` directories. They use the dummy rails app in `spec/dummy`
@@ -130,4 +170,3 @@ All contributions are welcome. Just fork the code, ensure your changes include a
130
170
 
131
171
  Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
132
172
  further details.
133
-
@@ -0,0 +1,5 @@
1
+ module ConfigurableEngine
2
+ class ConfigurablesController < ApplicationController
3
+ include ConfigurableEngine::ConfigurablesControllerMethods
4
+ end
5
+ end
@@ -1,4 +1,6 @@
1
1
  class Configurable < ActiveRecord::Base
2
+ serialize :value
3
+
2
4
  after_save :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
3
5
  after_destroy :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
4
6
 
@@ -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
- config = if ConfigurableEngine::Engine.config.use_cache
36
- Rails.cache.fetch("configurable_engine:#{key}") {
37
- find_by_name(key)
38
- }
39
- else
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.value
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.new(value.to_s)
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("configurable_engine:#{self.name}")
159
+ Rails.cache.delete(Configurable.cache_key self.name)
126
160
  end
127
161
  end
@@ -0,0 +1,31 @@
1
+ <div class='configurable-container'>
2
+
3
+ <div class="header">
4
+ <h2>Config</h2>
5
+ </div>
6
+
7
+ <div class="configurable-options">
8
+ <%= form_tag(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>
26
+ <%- end -%>
27
+
28
+ <%= submit_tag 'Save' %>
29
+ <%- end -%>
30
+ </div>
31
+ </div>
@@ -1,5 +1,3 @@
1
- Rails.application.routes.draw do
2
- namespace :admin do
3
- resource :configurable
4
- end
5
- end
1
+ ConfigurableEngine::Engine.routes.draw do
2
+ resource :configurable, path: '/'
3
+ end
@@ -1,2 +1,2 @@
1
1
  require 'configurable_engine/engine'
2
- require 'configurable_engine/configurables_controller'
2
+ require 'configurable_engine/configurables_controller_methods'
@@ -1,5 +1,5 @@
1
1
  module ConfigurableEngine
2
- module ConfigurablesController
2
+ module ConfigurablesControllerMethods
3
3
  def show
4
4
  @keys = Configurable.keys
5
5
  end
@@ -15,11 +15,11 @@ module ConfigurableEngine
15
15
  end
16
16
 
17
17
  if failures.empty?
18
- redirect_to admin_configurable_path, :notice => "Changes successfully updated"
18
+ redirect_to configurable_path, :notice => "Changes successfully updated"
19
19
  else
20
20
  flash[:error] = failures.flat_map(&:errors).flat_map(&:full_messages).join(',')
21
- redirect_to admin_configurable_path
21
+ redirect_to configurable_path
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -1,8 +1,10 @@
1
1
  module ConfigurableEngine
2
- class Engine < Rails::Engine
2
+ class Engine < ::Rails::Engine
3
+ engine_name "configurable"
4
+ isolate_namespace ConfigurableEngine
3
5
  config.use_cache = false
4
6
  config.generators do |g|
5
7
  g.test_framework :rspec
6
8
  end
7
9
  end
8
- end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module ConfigurableEngine
2
- VERSION = '0.4.6'
3
- end
2
+ VERSION = '2.0.0'
3
+ end
@@ -20,5 +20,9 @@ class InstallGenerator < Rails::Generators::Base
20
20
  copy_file 'configurable.yml', 'config/configurable.yml'
21
21
  migration_template 'migration.rb', 'db/migrate/create_configurables.rb'
22
22
  end
23
+
24
+ def mount_interface
25
+ route 'mount ConfigurableEngine::Engine, at: "/admin/configurable"'
26
+ end
23
27
  end
24
- end
28
+ end
@@ -1,4 +1,4 @@
1
- class CreateConfigurables < ActiveRecord::Migration
1
+ class CreateConfigurables < ActiveRecord::Migration[5.2]
2
2
  def self.up
3
3
  create_table :configurables do |t|
4
4
  t.string :name
@@ -14,4 +14,4 @@ class CreateConfigurables < ActiveRecord::Migration
14
14
  remove_index :configurables, :name
15
15
  drop_table :configurables
16
16
  end
17
- end
17
+ 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.6
4
+ version: 2.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: 2014-10-28 00:00:00.000000000 Z
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: 3.1.0
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: 3.1.0
28
- description: 'Configurable is a Rails 3/4 engine that allows you to set up config
29
- variables in a config file, specifying default values for all environmentspec. These
30
- variables can then be set on a per-app basis using a user facing configuration screen. '
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: []
@@ -38,12 +38,12 @@ files:
38
38
  - CHANGELOG.md
39
39
  - LICENSE.txt
40
40
  - README.md
41
- - app/controllers/admin/configurables_controller.rb
41
+ - app/controllers/configurable_engine/configurables_controller.rb
42
42
  - app/models/configurable.rb
43
- - app/views/admin/configurables/show.html.erb
43
+ - app/views/configurable_engine/configurables/show.html.erb
44
44
  - config/routes.rb
45
45
  - lib/configurable_engine.rb
46
- - lib/configurable_engine/configurables_controller.rb
46
+ - lib/configurable_engine/configurables_controller_methods.rb
47
47
  - lib/configurable_engine/engine.rb
48
48
  - lib/configurable_engine/version.rb
49
49
  - lib/generators/configurable_engine/install_generator.rb
@@ -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
- rubyforge_project:
72
- rubygems_version: 2.4.2
73
- signing_key:
71
+ rubygems_version: 3.0.3
72
+ signing_key:
74
73
  specification_version: 4
75
- summary: Database-backed configuration for Rails 3, with defaults from config file.
74
+ summary: Database-backed configuration for Rails 4, with defaults from config file.
76
75
  test_files: []
@@ -1,3 +0,0 @@
1
- class Admin::ConfigurablesController < ApplicationController
2
- include ConfigurableEngine::ConfigurablesController
3
- end
@@ -1,24 +0,0 @@
1
- <h2>Config</h2>
2
-
3
- <%= form_tag(admin_configurable_path, :method => :put) do -%>
4
- <%- @keys.each do |key| -%>
5
- <%- options = Configurable.defaults[key] -%>
6
- <div class="configurable">
7
- <%= label_tag key, options[:name] %>
8
- <%- if options[:type] == 'boolean' %>
9
- <%= hidden_field_tag key, "0" %>
10
- <%= check_box_tag key, "1", Configurable.send(key) %>
11
- <%- elsif options[:type] == 'password' -%>
12
- <%= password_field_tag key, Configurable.send(key) %>
13
- <%- elsif options[:type] == 'text' -%>
14
- <%= text_area_tag key, Configurable.send(key) %>
15
- <%- elsif options[:type] == 'list' -%>
16
- <%= text_area_tag key, Configurable.serialized_value(key) -%>
17
- <%- else -%>
18
- <%= text_field_tag key, Configurable.send(key) %>
19
- <%- end -%>
20
- </div>
21
- <%- end -%>
22
-
23
- <%= submit_tag 'Save' %>
24
- <%- end -%>