rails-settings-cached 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/settings/install_generator.rb +11 -11
- data/lib/rails-settings-cached.rb +7 -7
- data/lib/rails-settings/base.rb +1 -1
- data/lib/rails-settings/default.rb +3 -3
- data/lib/rails-settings/extend.rb +2 -2
- data/lib/rails-settings/railtie.rb +1 -1
- data/lib/rails-settings/settings.rb +5 -6
- data/lib/rails-settings/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 888a069815b6bab14f9f929eafed86726e25ee9a039b8e39fc5f502cf6ee2296
|
4
|
+
data.tar.gz: 483ceb459e33194b5dc530b84ac12e4946b1d572cef3e5809c3304f52c05c7b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 403951a85e14d29e651fe77bd5d9a1c64ff31dbac0760bca38f0cbc94aceca99a7ff3ba6ea88663d4f116f8216be8930c7311d4d44aae83c9809ca8c3f9ab0f9
|
7
|
+
data.tar.gz: 338908c1df4dc0b0068011881bd4d98206c0e977cf6c1cf5e646559fd06a2d4ddcccafc54be9b53e17eb8267e50f90df0c620f6866f35677277fb4d6a184cd36
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rails/generators"
|
2
|
+
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
|
-
argument :name, type: :string, default:
|
9
|
+
argument :name, type: :string, default: "setting"
|
10
10
|
|
11
|
-
source_root File.expand_path(
|
11
|
+
source_root File.expand_path("../templates", __FILE__)
|
12
12
|
|
13
13
|
@@migrations = false
|
14
14
|
|
@@ -18,21 +18,21 @@ module Settings
|
|
18
18
|
(current_migration_number(dirname) + 1)
|
19
19
|
else
|
20
20
|
@@migrations = true
|
21
|
-
Time.now.utc.strftime(
|
21
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
22
22
|
end
|
23
23
|
else
|
24
|
-
format
|
24
|
+
format "%.3d", current_migration_number(dirname) + 1
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def install_setting
|
29
|
-
template
|
30
|
-
template
|
31
|
-
migration_template
|
29
|
+
template "model.rb", File.join("app/models", class_path, "#{file_name}.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
32
|
end
|
33
33
|
|
34
34
|
def rails5?
|
35
|
-
Rails.version.start_with?
|
35
|
+
Rails.version.start_with? "5"
|
36
36
|
end
|
37
37
|
|
38
38
|
def migration_version
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
1
|
+
require_relative "rails-settings/settings"
|
2
|
+
require_relative "rails-settings/base"
|
3
|
+
require_relative "rails-settings/scoped_settings"
|
4
|
+
require_relative "rails-settings/default"
|
5
|
+
require_relative "rails-settings/extend"
|
6
|
+
require_relative "rails-settings/railtie"
|
7
|
+
require_relative "rails-settings/version"
|
8
8
|
|
9
9
|
module RailsSettings
|
10
10
|
end
|
data/lib/rails-settings/base.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "digest/md5"
|
2
2
|
|
3
3
|
module RailsSettings
|
4
4
|
class Default < ::Hash
|
@@ -14,13 +14,13 @@ module RailsSettings
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def source_path
|
17
|
-
@source || Rails.root.join(
|
17
|
+
@source || Rails.root.join("config/app.yml")
|
18
18
|
end
|
19
19
|
|
20
20
|
def [](key)
|
21
21
|
# foo.bar.dar Nested fetch value
|
22
22
|
return instance[key] if instance.key?(key)
|
23
|
-
keys = key.to_s.split(
|
23
|
+
keys = key.to_s.split(".")
|
24
24
|
instance.dig(*keys)
|
25
25
|
end
|
26
26
|
|
@@ -17,11 +17,11 @@ module RailsSettings
|
|
17
17
|
scope :without_settings, lambda {
|
18
18
|
joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
|
19
19
|
settings.thing_type = '#{base_class.name}')")
|
20
|
-
.where(
|
20
|
+
.where("settings.id IS NULL")
|
21
21
|
}
|
22
22
|
|
23
23
|
scope :without_settings_for, lambda { |var|
|
24
|
-
where(
|
24
|
+
where("settings.id IS NULL")
|
25
25
|
.joins("LEFT JOIN settings ON (settings.thing_id = #{table_name}.#{primary_key} AND
|
26
26
|
settings.thing_type = '#{base_class.name}') AND settings.var = '#{var}'")
|
27
27
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailsSettings
|
2
2
|
class Railtie < Rails::Railtie
|
3
|
-
initializer
|
3
|
+
initializer "rails_settings.active_record.initialization" do
|
4
4
|
RailsSettings::Base.after_commit :rewrite_cache, on: %i(create update)
|
5
5
|
RailsSettings::Base.after_commit :expire_cache, on: %i(destroy)
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailsSettings
|
2
2
|
class Settings < ActiveRecord::Base
|
3
|
-
self.table_name = table_name_prefix +
|
3
|
+
self.table_name = table_name_prefix + "settings"
|
4
4
|
|
5
5
|
class SettingNotFound < RuntimeError; end
|
6
6
|
|
@@ -24,8 +24,8 @@ module RailsSettings
|
|
24
24
|
super(method, *args)
|
25
25
|
rescue NoMethodError
|
26
26
|
# set a value for a variable
|
27
|
-
if method_name[-1] ==
|
28
|
-
var_name = method_name.sub(
|
27
|
+
if method_name[-1] == "="
|
28
|
+
var_name = method_name.sub("=", "")
|
29
29
|
value = args.first
|
30
30
|
self[var_name] = value
|
31
31
|
else
|
@@ -46,7 +46,7 @@ module RailsSettings
|
|
46
46
|
|
47
47
|
# retrieve all settings as a hash (optionally starting with a given namespace)
|
48
48
|
def get_all(starting_with = nil)
|
49
|
-
vars = thing_scoped.select(
|
49
|
+
vars = thing_scoped.select("var, value")
|
50
50
|
vars = vars.where("var LIKE '#{starting_with}%'") if starting_with
|
51
51
|
result = {}
|
52
52
|
vars.each { |record| result[record.var] = record.value }
|
@@ -90,13 +90,12 @@ module RailsSettings
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def object(var_name)
|
93
|
-
return nil unless rails_initialized?
|
94
93
|
return nil unless table_exists?
|
95
94
|
thing_scoped.where(var: var_name.to_s).first
|
96
95
|
end
|
97
96
|
|
98
97
|
def thing_scoped
|
99
|
-
unscoped.where(
|
98
|
+
unscoped.where("thing_type is NULL and thing_id is NULL")
|
100
99
|
end
|
101
100
|
|
102
101
|
def source(filename)
|
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.7.
|
4
|
+
version: 0.7.1
|
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: 2018-06-
|
14
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|