Skip to content

Commit

Permalink
Fix old Rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
mikker committed Sep 21, 2023
1 parent beadb7f commit 6bbc2ff
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/rails-settings/setting_object.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RailsSettings
class SettingObject < ActiveRecord::Base
self.table_name = 'settings'
self.table_name = "settings"

belongs_to :target, :polymorphic => true

Expand All @@ -13,7 +13,7 @@ class SettingObject < ActiveRecord::Base
end
end

if ActiveRecord.version >= "7.1.0.beta1"
if ActiveRecord.version >= Gem::Version.new("7.1.0.beta1")
serialize :value, type: Hash
else
serialize :value, Hash
Expand All @@ -28,15 +28,15 @@ class SettingObject < ActiveRecord::Base
REGEX_SETTER = /\A([a-z]\w*)=\Z/i
REGEX_GETTER = /\A([a-z]\w*)\Z/i

def respond_to?(method_name, include_priv=false)
def respond_to?(method_name, include_priv = false)
super || method_name.to_s =~ REGEX_SETTER || _setting?(method_name)
end

def method_missing(method_name, *args, &block)
if block_given?
super
else
if attribute_names.include?(method_name.to_s.sub('=',''))
if attribute_names.include?(method_name.to_s.sub("=", ""))
super
elsif method_name.to_s =~ REGEX_SETTER && args.size == 1
_set_value($1, args.first)
Expand All @@ -48,15 +48,15 @@ def method_missing(method_name, *args, &block)
end
end

protected
protected
if RailsSettings.can_protect_attributes?
# Simulate attr_protected by removing all regular attributes
def sanitize_for_mass_assignment(attributes, role = nil)
attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at')
attributes.except("id", "var", "value", "target_id", "target_type", "created_at", "updated_at")
end
end

private
private
def _get_value(name)
if value[name].nil?
default_value = _get_default_value(name)
Expand All @@ -65,17 +65,17 @@ def _get_value(name)
value[name]
end
end

def _get_default_value(name)
default_value = _target_class.default_settings[var.to_sym][name]

if default_value.respond_to?(:call)
default_value.call(target)
else
default_value
end
end

def _deep_dup(nested_hashes_and_or_arrays)
Marshal.load(Marshal.dump(nested_hashes_and_or_arrays))
end
Expand Down

0 comments on commit 6bbc2ff

Please sign in to comment.