Class: Pachinko
- Inherits:
-
Object
- Object
- Pachinko
- Defined in:
- lib/pachinko.rb
Overview
Example format of a patch: class YourPatch < Pachinko
# name: any string naming this patch
def name
'Example Patch Creating FabricatedClass'
end
# relevant?: a method that returns true only if the patch needs to be applied
def relevant?
!defined?(FabricatedClass)
end
# PATCH: A constant which contains a lambda which applies the patch
# Reason for this is that you can't reopen classes in methods...
PATCH = ->{
class ::FabricatedClass; end
}
end
Constant Summary collapse
- PATCH_PRIORITY =
Allows you to prioritize certain patch files first, such as core object patches
lambda { |p| p =~ /\/(hash|string|array|object)/i ? ' ' : p }
Class Attribute Summary collapse
-
.last_patch ⇒ Object
Returns the value of attribute last_patch.
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
- .development_mode? ⇒ Boolean
- .last_results ⇒ Object
- .mute? ⇒ Boolean
- .run(*args) ⇒ Object
- .run_if_needed ⇒ Object
- .test_mode? ⇒ Boolean
Instance Method Summary collapse
- #applied? ⇒ Boolean
-
#irrelevant? ⇒ Boolean
Overridable in subclasses, although not recommended Should return true if the patch was applied (which in most cases means it’s also no longer applicable).
- #name ⇒ Object
-
#relevant? ⇒ Boolean
This method returns a boolean that actually checks the mechanics of whatever the patch is supposed to fix.
- #run(force_plain_output = false) ⇒ Object
- #success? ⇒ Boolean
Class Attribute Details
.last_patch ⇒ Object
Returns the value of attribute last_patch.
39 40 41 |
# File 'lib/pachinko.rb', line 39 def last_patch @last_patch end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
24 25 26 |
# File 'lib/pachinko.rb', line 24 def results @results end |
Class Method Details
.development_mode? ⇒ Boolean
45 46 47 |
# File 'lib/pachinko.rb', line 45 def development_mode? defined?(Rails) && defined?(::Rails.env) && ::Rails.env.development? end |
.last_results ⇒ Object
55 56 57 |
# File 'lib/pachinko.rb', line 55 def last_results last_patch.results end |
.mute? ⇒ Boolean
34 35 36 |
# File 'lib/pachinko.rb', line 34 def self.mute? ENV['MUTE_PACHINKO'] end |
.run(*args) ⇒ Object
41 42 43 |
# File 'lib/pachinko.rb', line 41 def run(*args) new.run(*args) end |
.run_if_needed ⇒ Object
44 45 46 |
# File 'lib/pachinko.rb', line 44 def run(*args) new.run(*args) end |
.test_mode? ⇒ Boolean
48 49 50 51 52 53 54 |
# File 'lib/pachinko.rb', line 48 def test_mode? if defined?(Rails) && defined?(::Rails.env) ::Rails.env.test? else true end end |
Instance Method Details
#applied? ⇒ Boolean
30 31 32 |
# File 'lib/pachinko.rb', line 30 def applied? @applied end |
#irrelevant? ⇒ Boolean
Overridable in subclasses, although not recommended Should return true if the patch was applied (which in most cases means it’s also no longer applicable)
75 76 77 |
# File 'lib/pachinko.rb', line 75 def irrelevant? !relevant? end |
#name ⇒ Object
63 64 65 |
# File 'lib/pachinko.rb', line 63 def name raise NotImplementedError, "Your patch doesn't define a 'name' method... please override in your patch class" end |
#relevant? ⇒ Boolean
This method returns a boolean that actually checks the mechanics of whatever the patch is supposed to fix. It should return true if the patch still needs to be applied, and false after it has been applied or if it doesn’t need to be applied.
69 70 71 |
# File 'lib/pachinko.rb', line 69 def relevant? raise NotImplementedError, "Your patch doesn't define a 'relevant?' method which tests whether it is necessary... please override in your patch class" end |
#run(force_plain_output = false) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pachinko.rb', line 79 def run(force_plain_output = false) @force_plain_output = force_plain_output @success = false @applied = false output_msgs = [] output_msgs_warning = [] if relevant? apply @applied = true # Check to see if the patch is no longer needed (i.e., the test is valid, and the patch worked) if irrelevant? output_msgs << @success = true else output_msgs_warning << end else output_msgs_warning << end if !output_msgs.empty? && (Pachinko.development_mode? || force_plain_output) log_success output_msgs.join("\n") unless Pachinko.mute? end if !output_msgs_warning.empty? log_warning output_msgs_warning.join("\n") end Pachinko.last_patch = self @results = output_msgs_warning | output_msgs self end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/pachinko.rb', line 26 def success? @success end |