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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac720065903da7de8fed10d171d0145ddeabb6b7d7f0a1b6c66f7e497c79ddb1
4
- data.tar.gz: 2b20fdde2d824978ef981935b88faf7e3773469bacaa7520dcbcf59376bf0d76
3
+ metadata.gz: 888a069815b6bab14f9f929eafed86726e25ee9a039b8e39fc5f502cf6ee2296
4
+ data.tar.gz: 483ceb459e33194b5dc530b84ac12e4946b1d572cef3e5809c3304f52c05c7b9
5
5
  SHA512:
6
- metadata.gz: eab7e6fb1eb995cf1d4e548812964ca6ac342e47c2792598f3db835b6611c31b13dd89e8d0973cf545799dbfeb8aa5ef5bed307a0559ee82484a37ff4df01ceb
7
- data.tar.gz: 67139f1e6fea2edc490f43fa7a782a245a1b40b82ece38e4bcb479e18752511f2420131add354a48f5140ebf7130bf1ba8af6349336fa483d6e809625f80a7a6
6
+ metadata.gz: 403951a85e14d29e651fe77bd5d9a1c64ff31dbac0760bca38f0cbc94aceca99a7ff3ba6ea88663d4f116f8216be8930c7311d4d44aae83c9809ca8c3f9ab0f9
7
+ data.tar.gz: 338908c1df4dc0b0068011881bd4d98206c0e977cf6c1cf5e646559fd06a2d4ddcccafc54be9b53e17eb8267e50f90df0c620f6866f35677277fb4d6a184cd36
@@ -1,14 +1,14 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
1
+ require "rails/generators"
2
+ require "rails/generators/migration"
3
3
 
4
4
  module Settings
5
5
  class InstallGenerator < Rails::Generators::NamedBase
6
- desc 'Generate RailsSettings files.'
6
+ desc "Generate RailsSettings files."
7
7
  include Rails::Generators::Migration
8
8
 
9
- argument :name, type: :string, default: 'setting'
9
+ argument :name, type: :string, default: "setting"
10
10
 
11
- source_root File.expand_path('../templates', __FILE__)
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('%Y%m%d%H%M%S')
21
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
22
22
  end
23
23
  else
24
- format '%.3d', current_migration_number(dirname) + 1
24
+ format "%.3d", current_migration_number(dirname) + 1
25
25
  end
26
26
  end
27
27
 
28
28
  def install_setting
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
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? '5'
35
+ Rails.version.start_with? "5"
36
36
  end
37
37
 
38
38
  def migration_version
@@ -1,10 +1,10 @@
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'
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
@@ -22,7 +22,7 @@ module RailsSettings
22
22
  scope << @cache_prefix.call if @cache_prefix
23
23
  scope << "#{scope_object.class.name}-#{scope_object.id}" if scope_object
24
24
  scope << var_name.to_s
25
- scope.join('/')
25
+ scope.join("/")
26
26
  end
27
27
 
28
28
  def [](key)
@@ -1,4 +1,4 @@
1
- require 'digest/md5'
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('config/app.yml')
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('settings.id IS NULL')
20
+ .where("settings.id IS NULL")
21
21
  }
22
22
 
23
23
  scope :without_settings_for, lambda { |var|
24
- where('settings.id IS NULL')
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 'rails_settings.active_record.initialization' do
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 + 'settings'
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('var, value')
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('thing_type is NULL and thing_id is NULL')
98
+ unscoped.where("thing_type is NULL and thing_id is NULL")
100
99
  end
101
100
 
102
101
  def source(filename)
@@ -1,7 +1,7 @@
1
1
  module RailsSettings
2
2
  class << self
3
3
  def version
4
- '0.7.0'
4
+ "0.7.1"
5
5
  end
6
6
  end
7
7
  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.7.0
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-13 00:00:00.000000000 Z
14
+ date: 2018-06-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails