pachinko 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pachinko.rb +14 -10
  2. metadata +1 -1
@@ -12,11 +12,11 @@ require 'ansi'
12
12
  # def relevant?
13
13
  # !defined?(FabricatedClass)
14
14
  # end
15
- # # PATCH: A constant which contains a lambda which applies the patch
15
+ # # patch: a method which you pass a block which applies the patch
16
16
  # # Reason for this is that you can't reopen classes in methods...
17
- # PATCH = ->{
17
+ # patch do
18
18
  # class ::FabricatedClass; end
19
- # }
19
+ # end
20
20
  # end
21
21
 
22
22
  class Pachinko
@@ -37,29 +37,33 @@ class Pachinko
37
37
 
38
38
  class << self
39
39
  attr_accessor :last_patch
40
+ attr_reader :patch_block
41
+
42
+ def patch(&block)
43
+ @patch_block = block
44
+ end
40
45
 
41
46
  def run(*args)
42
47
  new.run(*args)
43
48
  end
44
- alias_method :run_if_needed, :run
49
+
45
50
  def development_mode?
46
- defined?(Rails) && defined?(::Rails.env) && ::Rails.env.development?
51
+ defined?(::Rails) && defined?(::Rails.env) && ::Rails.env.development?
47
52
  end
53
+
48
54
  def test_mode?
49
- if defined?(Rails) && defined?(::Rails.env)
55
+ if defined?(::Rails) && defined?(::Rails.env)
50
56
  ::Rails.env.test?
51
57
  else
52
58
  true
53
59
  end
54
60
  end
61
+
55
62
  def last_results
56
63
  last_patch.results
57
64
  end
58
65
  end
59
66
 
60
- # Allows you to prioritize certain patch files first, such as core object patches
61
- PATCH_PRIORITY = lambda { |p| p =~ /\/(hash|string|array|object)/i ? ' ' : p }
62
-
63
67
  def name
64
68
  raise NotImplementedError, "Your patch doesn't define a 'name' method... please override in your patch class"
65
69
  end
@@ -109,7 +113,7 @@ class Pachinko
109
113
  private
110
114
  def apply
111
115
  begin
112
- self.class::PATCH.call
116
+ self.class.patch_block.call
113
117
  rescue NameError => e
114
118
  e.message << "\nNOTE TO PATCH DEVS: If you are writing a patch, it is possible that you just have to root-namespace any relevant classes in your PATCH block with a double colon (::) in front, to avoid this error!"
115
119
  raise e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pachinko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: