Module: Appraisal::Hooks
- Defined in:
- lib/appraisal/hooks.rb
Overview
Lifecycle hooks used by companion gems to extend Appraisal without monkey-patching command or generation internals.
Defined Under Namespace
Classes: GemfileContext
Constant Summary collapse
- GEMFILE_TRANSFORM_MUTEX =
Mutex.new
- GEMFILE_TRANSFORMS =
[].freeze
Class Method Summary collapse
- .reset! ⇒ Object
- .run_transform_gemfile(appraisal, path, content) ⇒ Object
- .transform_gemfile(&block) ⇒ Object
Class Method Details
.reset! ⇒ Object
43 44 45 46 47 |
# File 'lib/appraisal/hooks.rb', line 43 def reset! GEMFILE_TRANSFORM_MUTEX.synchronize do set_gemfile_transforms([]) end end |
.run_transform_gemfile(appraisal, path, content) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/appraisal/hooks.rb', line 30 def run_transform_gemfile(appraisal, path, content) context = GemfileContext.new(appraisal, path, content) gemfile_transforms.each do |hook| result = if hook.arity == 1 hook.call(context.content) else hook.call(context.content, context) end context.content = result unless result.nil? end context.content end |
.transform_gemfile(&block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/appraisal/hooks.rb', line 22 def transform_gemfile(&block) raise ArgumentError, "transform_gemfile requires a block" unless block GEMFILE_TRANSFORM_MUTEX.synchronize do set_gemfile_transforms(gemfile_transforms + [block]) end end |