Module: RearmedRails

Defined in:
lib/rearmed_rails.rb,
lib/rearmed_rails/version.rb,
lib/rearmed_rails/exceptions.rb,
lib/rearmed_rails/monkey_patches/helpers.rb,
lib/generators/rearmed_rails/setup_generator.rb

Defined Under Namespace

Modules: Exceptions, RailsHelpers Classes: SetupGenerator

Constant Summary collapse

VERSION =
"2.0.2"

Class Method Summary collapse

Class Method Details

.apply_patches!Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rearmed_rails.rb', line 42

def self.apply_patches!
  if @applied 
    raise ::RearmedRails::Exceptions::PatchesAlreadyAppliedError.new
  else
    patches_folder = File.expand_path('../rearmed_rails/monkey_patches', __FILE__)
    Dir[File.join(patches_folder, '**/*.rb')].each do |filename| 
      require filename
    end

    @applied = true 
  end
end

.enabled_patchesObject


38
39
40
# File 'lib/rearmed_rails.rb', line 38

def self.enabled_patches
  @enabled_patches
end

.enabled_patches=(val) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rearmed_rails.rb', line 11

def self.enabled_patches=(val)
  if @applied
    raise ::RearmedRails::Exceptions::PatchesAlreadyAppliedError.new
  else
    if val.nil?
      @enabled_patches = Marshal.load(Marshal.dump(DEFAULT_PATCHES)) 
    elsif val == :all
      @enabled_patches = val
    elsif val.is_a?(Hash)
      @enabled_patches = Marshal.load(Marshal.dump(DEFAULT_PATCHES)) 

      DEFAULT_PATCHES.keys.each do |k|
        methods = val[k] || val[k.to_sym]
        if methods
          if methods.is_a?(Hash) || methods == true
            @enabled_patches[k] = methods
          else
            raise TypeError.new('Invalid value within the hash passed to Rearmed.enabled_patches=')
          end
        end
      end
    else
      raise TypeError.new('Invalid value passed to Rearmed.enabled_patches=')
    end
  end
end