rails-settings-cached 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/generators/settings/install_generator.rb +11 -3
- data/lib/generators/settings/templates/migration.rb +1 -1
- data/lib/rails-settings/base.rb +2 -1
- data/lib/rails-settings/cached_settings.rb +2 -1
- data/lib/rails-settings/default.rb +2 -2
- data/lib/rails-settings/settings.rb +14 -20
- data/lib/rails-settings/version.rb +1 -1
- metadata +73 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63487ca0f7161c9c7f7e4cb6241bf07551882055
|
4
|
+
data.tar.gz: 2498ef10d3a2a6d16f5b75ba1444f8ffeab5bf31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67341b519564882fa590bbd1a535a8192095b85ded29646e9ee00e6b29bb9a8985c78d07a3f41fdfef57bb51ae5df9ba07bf51fd198bef5200a8c64c816df85c
|
7
|
+
data.tar.gz: fcbeaae817222dd48f874ab7b0c09ffca3b79ce19d4265e9ca57018012314a0228cc493d870efd167d957d0a23d5dd47c387dbfe788b733b8ae3b36e4df92e5e
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ of object. Strings, numbers, arrays, or any object.
|
|
9
9
|
|
10
10
|
## Status
|
11
11
|
|
12
|
-
[![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![CI Status](https://
|
12
|
+
[![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![CI Status](https://travis-ci.org/huacnlee/rails-settings-cached.svg)](http://travis-ci.org/huacnlee/rails-settings-cached) [![Code Climate](https://codeclimate.com/github/huacnlee/rails-settings-cached/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/rails-settings-cached) [![codecov.io](https://codecov.io/github/huacnlee/rails-settings-cached/coverage.svg?branch=master)](https://codecov.io/github/huacnlee/rails-settings-cached?branch=master)
|
13
13
|
|
14
14
|
## Setup
|
15
15
|
|
@@ -253,7 +253,7 @@ app/views/admin/settings/edit.html.erb
|
|
253
253
|
```erb
|
254
254
|
<%= form_for(@setting, url: admin_setting_path(@setting.var), method: 'patch') do |f| %>
|
255
255
|
<label><%= @setting.var %></label>
|
256
|
-
<%= f.
|
256
|
+
<%= f.text_area :value, rows: 10 %>
|
257
257
|
<%= f.submit %>
|
258
258
|
<% end %>
|
259
259
|
```
|
@@ -3,7 +3,7 @@ require 'rails/generators/migration'
|
|
3
3
|
|
4
4
|
module Settings
|
5
5
|
class InstallGenerator < Rails::Generators::NamedBase
|
6
|
-
desc
|
6
|
+
desc 'Generate RailsSettings files.'
|
7
7
|
include Rails::Generators::Migration
|
8
8
|
|
9
9
|
argument :name, type: :string, default: 'setting'
|
@@ -27,8 +27,16 @@ module Settings
|
|
27
27
|
|
28
28
|
def install_setting
|
29
29
|
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
30
|
-
template 'app.yml', File.join('config',
|
31
|
-
migration_template 'migration.rb', 'db/migrate/create_settings.rb'
|
30
|
+
template 'app.yml', File.join('config', 'app.yml')
|
31
|
+
migration_template 'migration.rb', 'db/migrate/create_settings.rb', migration_version: migration_version
|
32
|
+
end
|
33
|
+
|
34
|
+
def rails5?
|
35
|
+
Rails.version.start_with? '5'
|
36
|
+
end
|
37
|
+
|
38
|
+
def migration_version
|
39
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5?
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
data/lib/rails-settings/base.rb
CHANGED
@@ -47,7 +47,8 @@ module RailsSettings
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def save_default(key, value)
|
50
|
-
Kernel.warn 'DEPRECATION WARNING: RailsSettings save_default is deprecated
|
50
|
+
Kernel.warn 'DEPRECATION WARNING: RailsSettings save_default is deprecated ' \
|
51
|
+
'and it will removed in 0.7.0. ' \
|
51
52
|
'Please use YAML file for default setting.'
|
52
53
|
return false unless self[key].nil?
|
53
54
|
self[key] = value
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module RailsSettings
|
2
2
|
class CachedSettings < Base
|
3
3
|
def self.inherited(subclass)
|
4
|
-
Kernel.warn 'DEPRECATION WARNING: RailsSettings::CachedSettings is deprecated
|
4
|
+
Kernel.warn 'DEPRECATION WARNING: RailsSettings::CachedSettings is deprecated ' \
|
5
|
+
'and it will removed in 0.7.0. ' \
|
5
6
|
'Please use RailsSettings::Base instead.'
|
6
7
|
super(subclass)
|
7
8
|
end
|
@@ -19,7 +19,7 @@ module RailsSettings
|
|
19
19
|
|
20
20
|
def [](key)
|
21
21
|
# foo.bar.dar Nested fetch value
|
22
|
-
return instance[key] if instance.
|
22
|
+
return instance[key] if instance.key?(key)
|
23
23
|
keys = key.to_s.split('.')
|
24
24
|
val = instance
|
25
25
|
keys.each do |k|
|
@@ -40,7 +40,7 @@ module RailsSettings
|
|
40
40
|
content = open(self.class.source_path).read
|
41
41
|
hash = content.empty? ? {} : YAML.load(ERB.new(content).result).to_hash
|
42
42
|
hash = hash[Rails.env] || {}
|
43
|
-
|
43
|
+
replace hash
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -18,6 +18,7 @@ module RailsSettings
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
# get or set a variable with the variable as the called method
|
21
|
+
# rubocop:disable Style/MethodMissing
|
21
22
|
def method_missing(method, *args)
|
22
23
|
method_name = method.to_s
|
23
24
|
super(method, *args)
|
@@ -47,19 +48,9 @@ module RailsSettings
|
|
47
48
|
def get_all(starting_with = nil)
|
48
49
|
vars = thing_scoped.select('var, value')
|
49
50
|
vars = vars.where("var LIKE '#{starting_with}%'") if starting_with
|
50
|
-
|
51
51
|
result = {}
|
52
|
-
vars.each
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
defaults = {}
|
57
|
-
if Default.enabled?
|
58
|
-
defaults = starting_with.nil? ? Default.instance : Default.instance.select { |key, _| key.to_s.start_with?(starting_with) }
|
59
|
-
end
|
60
|
-
|
61
|
-
result.reverse_merge! defaults
|
62
|
-
|
52
|
+
vars.each { |record| result[record.var] = record.value }
|
53
|
+
result.reverse_merge!(default_settings(starting_with))
|
63
54
|
result.with_indifferent_access
|
64
55
|
end
|
65
56
|
|
@@ -70,14 +61,9 @@ module RailsSettings
|
|
70
61
|
|
71
62
|
# get a setting value by [] notation
|
72
63
|
def [](var_name)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
val = Default[var_name]
|
77
|
-
else
|
78
|
-
val = nil
|
79
|
-
end
|
80
|
-
val
|
64
|
+
val = object(var_name)
|
65
|
+
return val.value if val
|
66
|
+
return Default[var_name] if Default.enabled?
|
81
67
|
end
|
82
68
|
|
83
69
|
# set a setting value by [] notation
|
@@ -120,6 +106,14 @@ module RailsSettings
|
|
120
106
|
def rails_initialized?
|
121
107
|
Rails.application && Rails.application.initialized?
|
122
108
|
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def default_settings(starting_with = nil)
|
113
|
+
return {} unless Default.enabled?
|
114
|
+
return Default.instance if starting_with.nil?
|
115
|
+
Default.instance.select { |key, _| key.to_s.start_with?(starting_with) }
|
116
|
+
end
|
123
117
|
end
|
124
118
|
end
|
125
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-settings-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -27,6 +27,76 @@ dependencies:
|
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 4.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sqlite3
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rubocop
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: rspec
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: codecov
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
30
100
|
description: "\n This is improved from rails-settings, added caching.\n Settings
|
31
101
|
plugin for Rails that makes managing a table of global key,\n value pairs easy.
|
32
102
|
Think of it like a global Hash stored in you database,\n that uses simple ActiveRecord
|
@@ -71,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
141
|
version: '0'
|
72
142
|
requirements: []
|
73
143
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.6.11
|
75
145
|
signing_key:
|
76
146
|
specification_version: 4
|
77
147
|
summary: Settings plugin for Rails that makes managing a table of global keys.
|