ledermann-rails-settings-update 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +153 -0
- data/app/controllers/concerns/ledermann_rails_settings_update/update_settings.rb +23 -0
- data/lib/ledermann-rails-settings-update.rb +8 -0
- data/lib/ledermann-rails-settings-update/engine.rb +6 -0
- data/lib/ledermann-rails-settings-update/railtie.rb +13 -0
- data/lib/ledermann-rails-settings-update/version.rb +5 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: adb5aa9911555c3a8f8c78131c6e4baefcf2bc2652ee9be7b379b3b2039d4084
|
4
|
+
data.tar.gz: 480c15842a308049eee28d7d6f0f62ebede33f9542422de9ede2d5967e5ce3e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d5d9fb804e3b64d54f10499dc41ffd9fbd954a6c60e0ce70d2d61daf0f6a9c683daa11d3af7b1e316f839198bc39f10a17f669aac611b111e1c605d54fd4823
|
7
|
+
data.tar.gz: 477a98b5fdfd5bf328b221dc20dc50f3dcf57155e00e2c87123f277dc684f8e662055fc6b0948c2c36d38fbcbf3c0d6ca457caae8cc2de894bb7b63ab8ed1574
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jonas Hübotter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# Ledermann Rails Settings Update
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ledermann-rails-settings-update.svg)](https://badge.fury.io/rb/ledermann-rails-settings-update) <img src="https://travis-ci.org/jonhue/ledermann-rails-settings-update.svg?branch=master" />
|
4
|
+
|
5
|
+
Simplifying updating settings from controllers. Ledermann Rails Settings Update depends on [Ledermann Rails Settings](https://github.com/ledermann/rails-settings).
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## Table of Contents
|
10
|
+
|
11
|
+
* [Installation](#installation)
|
12
|
+
* [Usage](#usage)
|
13
|
+
* [Forms](#forms)
|
14
|
+
* [Controllers](#controllers)
|
15
|
+
* [To Do](#to-do)
|
16
|
+
* [Contributing](#contributing)
|
17
|
+
* [Contributors](#contributors)
|
18
|
+
* [Semantic versioning](#semantic-versioning)
|
19
|
+
* [License](#license)
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
**Note:** Before installing Ledermann Rails Settings Update make sure to setup the original [Ledermann Rails Settings](https://github.com/ledermann/rails-settings) gem.
|
26
|
+
|
27
|
+
Ledermann Rails Settings Update works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'ledermann-rails-settings-update'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install ledermann-rails-settings-update
|
40
|
+
|
41
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'ledermann-rails-settings-update', github: 'jonhue/ledermann-rails-settings-update'
|
45
|
+
```
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
### Forms
|
52
|
+
|
53
|
+
Let's say we have this `Post` model:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Post < ApplicationRecord
|
57
|
+
has_settings do |s|
|
58
|
+
s.key :preferences, defaults: { language: 'en' }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
To update this `preferences/language` setting, a form could look like this:
|
64
|
+
|
65
|
+
```haml
|
66
|
+
= simple_form_for @post, url: @post, html: { method: :put } do |f|
|
67
|
+
= f.input :title
|
68
|
+
= text_field_tag 'post[settings][preferences][language]'
|
69
|
+
= f.input :submit
|
70
|
+
```
|
71
|
+
|
72
|
+
### Controllers
|
73
|
+
|
74
|
+
Here is a corresponding controller:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class PostsController < ApplicationController
|
78
|
+
|
79
|
+
def update
|
80
|
+
@post = Post.find params[:id]
|
81
|
+
update_settings @post
|
82
|
+
@post.update! post_params
|
83
|
+
redirect_back fallback_location: root_path, notice: 'Post updated'
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def post_params
|
89
|
+
params.require(:post).permit(:title)
|
90
|
+
end
|
91
|
+
|
92
|
+
def settings_params
|
93
|
+
params.require(:post).permit(
|
94
|
+
settings: [
|
95
|
+
preferences: [:language]
|
96
|
+
]
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
**Note:** The `private` `settings_params` method is required.
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
## To Do
|
108
|
+
|
109
|
+
[Here](https://github.com/jonhue/ledermann-rails-settings-update/projects/1) is the full list of current projects.
|
110
|
+
|
111
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/ledermann-rails-settings-update/issues/new).
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
We hope that you will consider contributing to Ledermann Rails Settings Update. Please read this short overview for some information about how to get started:
|
118
|
+
|
119
|
+
[Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
|
120
|
+
|
121
|
+
### Contributors
|
122
|
+
|
123
|
+
Give the people some :heart: who are working on this project. See them all at:
|
124
|
+
|
125
|
+
https://github.com/jonhue/ledermann-rails-settings-update/graphs/contributors
|
126
|
+
|
127
|
+
### Semantic Versioning
|
128
|
+
|
129
|
+
Ahoy Views follows Semantic Versioning 2.0 as defined at http://semver.org.
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
MIT License
|
134
|
+
|
135
|
+
Copyright (c) 2018 Jonas Hübotter
|
136
|
+
|
137
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
138
|
+
of this software and associated documentation files (the "Software"), to deal
|
139
|
+
in the Software without restriction, including without limitation the rights
|
140
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
141
|
+
copies of the Software, and to permit persons to whom the Software is
|
142
|
+
furnished to do so, subject to the following conditions:
|
143
|
+
|
144
|
+
The above copyright notice and this permission notice shall be included in all
|
145
|
+
copies or substantial portions of the Software.
|
146
|
+
|
147
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
148
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
149
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
150
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
151
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
152
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
153
|
+
SOFTWARE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LedermannRailsSettingsUpdate
|
2
|
+
module UpdateSettings
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def update_settings instance
|
9
|
+
settings = settings_params[:settings]
|
10
|
+
settings.each do |key, value|
|
11
|
+
value.each do |k, v|
|
12
|
+
if v == 'true' || v == '1'
|
13
|
+
settings[key][k] = true
|
14
|
+
elsif v == 'false' || v == '0'
|
15
|
+
settings[key][k] = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
instance.settings(key.to_sym).update_attributes value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module LedermannRailsSettingsUpdate
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'ledermann-rails-settings-update.action_controller' do
|
7
|
+
ActiveSupport.on_load :action_controller do
|
8
|
+
include LedermannRailsSettingsUpdate::UpdateSettings
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ledermann-rails-settings-update
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Hübotter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ledermann-rails-settings
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.52'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.52'
|
97
|
+
description: Simplifying updating settings from controllers.
|
98
|
+
email: me@jonhue.me
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- CHANGELOG.md
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- app/controllers/concerns/ledermann_rails_settings_update/update_settings.rb
|
107
|
+
- lib/ledermann-rails-settings-update.rb
|
108
|
+
- lib/ledermann-rails-settings-update/engine.rb
|
109
|
+
- lib/ledermann-rails-settings-update/railtie.rb
|
110
|
+
- lib/ledermann-rails-settings-update/version.rb
|
111
|
+
homepage: https://github.com/jonhue/ledermann-rails-settings-update
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2.3'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.7.4
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Simplifying updating settings from controllers
|
135
|
+
test_files: []
|