Module: Crispy::CrispyInternal::ConstChanger

Defined in:
lib/crispy/crispy_internal/const_changer.rb

Class Method Summary collapse

Class Method Details

.change_by_full_name(full_const_name, value) ⇒ Object



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

def change_by_full_name full_const_name, value
  const_names = full_const_name.split('::'.freeze)

  const_names.shift if const_names.first.empty?

  target_const_name = const_names.pop

  module_containing_target_const =
    const_names.inject(::Kernel) do|const_value, const_name|
      const_value.const_get const_name
    end

  saved_value = module_containing_target_const.module_eval do
    remove_const target_const_name
  end
  module_containing_target_const.const_set target_const_name, value

  saved_value
end

.recover_allObject



33
34
35
36
37
# File 'lib/crispy/crispy_internal/const_changer.rb', line 33

def recover_all
  @registry.each do|full_const_name, saved_value|
    self.change_by_full_name(full_const_name, saved_value)
  end
end

.save(full_const_name, value) ⇒ Object



29
30
31
# File 'lib/crispy/crispy_internal/const_changer.rb', line 29

def save full_const_name, value
  @registry[full_const_name] = value
end