Module: PayDirt::UseCase
- Included in:
- Base
- Defined in:
- lib/pay_dirt/use_case.rb
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(opt, opts) ⇒ Object
- #load_option(option, options) ⇒ Object
-
#load_options(*option_names, options) ⇒ Object
Load instance variables from the provided hash of dependencies.
-
#result(success, data = nil) ⇒ Object
Returns a result object representing success.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 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 43 44 45 46 47 48 49 |
# File 'lib/pay_dirt/use_case.rb', line 3 def self.included(base) # Load instance variables from the provided hash of dependencies. # # Raises if any required dependencies are missing from +options+ hash. # # @param [List<String,Symbol>] # option_names list of keys representing required dependencies # # @param [Hash] # options A hash of dependencies # # @public def (*option_names, ) # Load required options option_names.each { |o| = load_option(o, ) } # Load remaining options .each_key { |o| = load_option(o, ) } end # Returns a result object representing success. # # @param [List<String,Symbol>] # success should the result be +#successful?+ # # @param [Object] # data (nil) optional, an object containing information # # @public def result(success, data = nil) PayDirt::Result.new(success: success, data: data) end private # @private def load_option(option, ) instance_variable_set("@#{option}", fetch(option, )) .delete(option) return end # @private def fetch(opt, opts) opts.fetch(opt.to_sym) { raise "Missing required option: #{opt}" } end end |
Instance Method Details
#fetch(opt, opts) ⇒ Object
46 47 48 |
# File 'lib/pay_dirt/use_case.rb', line 46 def fetch(opt, opts) opts.fetch(opt.to_sym) { raise "Missing required option: #{opt}" } end |
#load_option(option, options) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/pay_dirt/use_case.rb', line 38 def load_option(option, ) instance_variable_set("@#{option}", fetch(option, )) .delete(option) return end |
#load_options(*option_names, options) ⇒ Object
Load instance variables from the provided hash of dependencies.
Raises if any required dependencies are missing from options
hash.
15 16 17 18 19 20 21 |
# File 'lib/pay_dirt/use_case.rb', line 15 def (*option_names, ) # Load required options option_names.each { |o| = load_option(o, ) } # Load remaining options .each_key { |o| = load_option(o, ) } end |