Skip to content

Commit

Permalink
Use Activity::DSL::Linear::Helper to introduce macros in activities s…
Browse files Browse the repository at this point in the history
…cope
  • Loading branch information
yogeshjain999 committed May 22, 2020
1 parent 270f40f commit 540582b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/trailblazer/macro.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "forwardable"
require "trailblazer/activity"
require "trailblazer/activity/dsl/linear" # TODO: remove this dependency
require "trailblazer/activity/dsl/linear"
require "trailblazer/operation" # TODO: remove this dependency

require "trailblazer/macro/model"
Expand All @@ -12,18 +13,16 @@

module Trailblazer
module Macro
# All macros sit in the {Trailblazer::Macro} namespace, where we forward calls from
# operations and activities to.
def self.forward_macros(target)
target.singleton_class.def_delegators Trailblazer::Macro, :Model, :Wrap, :Rescue, :Nested
target.const_set(:Policy, Trailblazer::Macro::Policy)
end
end
end

# TODO: Forwardable.def_delegators(Operation, Macro, :Model, :Wrap) would be amazing. It really sucks to extend a foreign class.
# Trailblazer::Operation.singleton_class.extend Forwardable
# Trailblazer::Macro.forward_macros(Trailblazer::Operation)
# All macros sit in the {Trailblazer::Macro} namespace, where we forward calls from
# operations and activities to.
module Activity::DSL::Linear::Helper
Policy = Trailblazer::Macro::Policy

Trailblazer::Activity::FastTrack.singleton_class.extend Forwardable
Trailblazer::Macro.forward_macros(Trailblazer::Activity::FastTrack) # monkey-patching sucks.
module ClassMethods
extend Forwardable
def_delegators Trailblazer::Macro, :Model, :Nested, :Wrap, :Rescue
end # ClassMethods
end # Helper
end
2 changes: 2 additions & 0 deletions trailblazer-macro.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "roar"
spec.add_development_dependency "trailblazer-developer"

spec.add_dependency "trailblazer-activity", ">= 0.10.0", "< 1.0.0"
spec.add_dependency "trailblazer-activity-dsl-linear", ">= 0.2.7", "< 1.0.0"
spec.add_dependency "trailblazer-operation", ">= 0.6.2" # TODO: this dependency will be removed.

spec.required_ruby_version = ">= 2.2.0"
Expand Down

0 comments on commit 540582b

Please sign in to comment.