Module: Caze::ClassMethods
- Defined in:
- lib/caze.rb
Instance Attribute Summary collapse
-
#transaction_handler ⇒ Object
Returns the value of attribute transaction_handler.
Instance Method Summary collapse
- #export(method_name, options = {}) ⇒ Object
- #has_use_case(use_case_name, use_case_class, options = {}) ⇒ Object
Instance Attribute Details
#transaction_handler ⇒ Object
Returns the value of attribute transaction_handler.
12 13 14 |
# File 'lib/caze.rb', line 12 def transaction_handler @transaction_handler end |
Instance Method Details
#export(method_name, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/caze.rb', line 44 def export(method_name, = {}) method_to_define = .fetch(:as) { method_name } define_singleton_method(method_to_define, Proc.new { |*args| use_case_object = args.empty? ? new : new(*args) use_case_object.send(method_name) }) end |
#has_use_case(use_case_name, use_case_class, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/caze.rb', line 14 def has_use_case(use_case_name, use_case_class, = {}) transactional = .fetch(:transactional) { false } raise_use_case_exception = .fetch(:raise_use_case_exception) { false } define_singleton_method(use_case_name, Proc.new do |*args| use_case = get_use_case_class(use_case_class) begin if transactional handler = self.transaction_handler unless handler raise NoTransactionMethodError, "This action should be executed inside a transaction. But no transaction handler was configured." end handler.transaction { use_case.send(use_case_name, *args) } else use_case.send(use_case_name, *args) end rescue => e if raise_use_case_exception raise UseCaseError.new(e).exception("#{use_case_class}: #{e.}") else raise e end end end) end |