class Dry::Facts::Command
Public Class Methods
call(input)
click to toggle source
# File lib/dry/facts/command.rb, line 29 def call(input) input .yield_self {|it| _enforce_input_contract_on it } .yield_self {|it| _execute_with it.to_hash } .yield_self {|it| _enforce_output_contract_on it } end
define_input_contract(&block)
click to toggle source
# File lib/dry/facts/command.rb, line 36 def define_input_contract &block @input_contract = Class .new(Dry::Struct::Value) .yield_self { |k| k.instance_eval(&block) if block } end
define_output_contract(&block)
click to toggle source
# File lib/dry/facts/command.rb, line 43 def define_output_contract &block @output_contract = Class .new(Dry::Struct::Value) .yield_self { |k| k.instance_eval(&block) if block } end
input_contract()
click to toggle source
# File lib/dry/facts/command.rb, line 13 def input_contract @input_contract if defined?(@input_contract) end
input_contract=(value)
click to toggle source
# File lib/dry/facts/command.rb, line 17 def input_contract= value @input_contract = value end
output_contract()
click to toggle source
# File lib/dry/facts/command.rb, line 21 def output_contract @output_contract if defined?(@output_contract) end
output_contract=(value)
click to toggle source
# File lib/dry/facts/command.rb, line 25 def output_contract= value @output_contract = value end
Private Class Methods
_enforce_contract_if_present(contract, data)
click to toggle source
# File lib/dry/facts/command.rb, line 74 def _enforce_contract_if_present contract, data if contract contract.new **data else data end end
_enforce_input_contract_on(input)
click to toggle source
# File lib/dry/facts/command.rb, line 52 def _enforce_input_contract_on input if defined?(self::InputContract) self::InputContract else self.input_contract end .yield_self {|c| _enforce_contract_if_present(c, input) } end
_enforce_output_contract_on(output)
click to toggle source
# File lib/dry/facts/command.rb, line 61 def _enforce_output_contract_on output if defined?(self::OutputContract) self::OutputContract else self.output_contract end .yield_self {|c| _enforce_contract_if_present(c, output) } end
_execute_with(input)
click to toggle source
# File lib/dry/facts/command.rb, line 70 def _execute_with input self.new.call input end