class RailsReadonlyInjector::Configuration

Attributes

changed_attributes[R]

@return [Hash] A hash of changed attributes

and their previous values
classes_to_exclude[R]
classes_to_include[R]
controller_rescue_action[R]
read_only[R]

Public Class Methods

new() click to toggle source
# File lib/rails_readonly_injector/configuration.rb, line 7
def initialize
  @read_only = false
  @controller_rescue_action = proc {}
  @classes_to_exclude = []

  @changed_attributes = {}
end

Public Instance Methods

classes_to_exclude=(klasses) click to toggle source

@param klasses [Array<Class>] The classes to exclude from being marked as read-only

# File lib/rails_readonly_injector/configuration.rb, line 49
def classes_to_exclude=(klasses)
  update_instance_variable('@classes_to_exclude', klasses)
end
classes_to_include=(klasses) click to toggle source

@param klasses [Array<Class>] The classes to mark as read-only

# File lib/rails_readonly_injector/configuration.rb, line 54
def classes_to_include=(klasses)
  update_instance_variable('@classes_to_include', klasses)
end
controller_rescue_action=(action) click to toggle source

@param action [Lambda, Proc] The action to execute when rescuing from

`ActiveRecord::RecordReadOnly` errors, within a controller
# File lib/rails_readonly_injector/configuration.rb, line 42
def controller_rescue_action=(action)
  raise 'A lambda or proc must be specified' unless action.respond_to? :call

  update_instance_variable('@controller_rescue_action', action)
end
dirty?() click to toggle source

@return [Boolean] Whether the configuration

has changed since the config was last reloaded
# File lib/rails_readonly_injector/configuration.rb, line 64
def dirty?
  !changed_attributes.empty?
end
read_only=(new_value) click to toggle source

@param new_value [Boolean] Whether the site should be in read-only mode

# File lib/rails_readonly_injector/configuration.rb, line 36
def read_only=(new_value)
  update_instance_variable('@read_only', new_value)
end

Private Instance Methods

reset_dirty_status!() click to toggle source

Resets the changed attributes hash, so that `#dirty?` returns false

# File lib/rails_readonly_injector/configuration.rb, line 88
def reset_dirty_status!
  @changed_attributes = {}
end
update_instance_variable(variable_name, new_value) click to toggle source

Updates the value of the specified instance variable and tracks the attribute's previous value (for `#dirty?`)

# File lib/rails_readonly_injector/configuration.rb, line 76
def update_instance_variable(variable_name, new_value)
  old_value = instance_variable_get(variable_name).freeze

  instance_variable_set(variable_name.to_sym, new_value)

  unless old_value == new_value
    changed_attributes[variable_name.to_s.delete('@').to_sym] = old_value
  end
end