Module: RailsReadonlyInjector

Defined in:
lib/rails_readonly_injector.rb,
lib/rails_readonly_injector/version.rb,
lib/rails_readonly_injector/configuration.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.config {|self.configuration| ... } ⇒ Configuration

Sets the desired configuration object, if a block is provided, and then returns the current configuration object.

Yields:

  • (self.configuration)

Returns:

  • (Configuration)

    The current configuration object.


44
45
46
47
48
# File 'lib/rails_readonly_injector.rb', line 44

def self.config
  yield self.configuration if block_given?

  self.configuration
end

.in_read_only_mode?Boolean

Returns the currently loaded `config.read_only` value.

Returns:

  • (Boolean)

    Whether the currently loaded config is set to read-only.


32
33
34
35
36
37
38
39
# File 'lib/rails_readonly_injector.rb', line 32

def self.in_read_only_mode?
  if self.config.dirty? && self.config.changed_attributes.has_key?(:read_only)
    # Return the previously stored value
    self.config.changed_attributes[:read_only]
  else
    self.config.send(:read_only)
  end
end

.reload!Object

Applies changes defined in the `config` object and resets `config.dirty?` to false


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_readonly_injector.rb', line 8

def self.reload!
  config.classes_to_include.each do |klass|
  
    # Ensure we restore classes that we want to exclude, to their defaults
    # in case they were previously marked as read-only.
    if config.classes_to_exclude.include? klass
      restore_readonly_method(klass)
      next
    end

    if self.config.send(:read_only)
      override_readonly_method(klass)
    else
      restore_readonly_method(klass)
    end
  end

  inject_error_handler_into_actioncontroller_base

  self.config.send(:reset_dirty_status!)
end