class Fixturama::Changes::Chain::ReturnAction
@private Return a specified value as a result of stubbing
Attributes
repeat[R]
Public Class Methods
new(**options)
click to toggle source
# File lib/fixturama/changes/chain/return_action.rb 15 def initialize(**options) 16 @value = value_from(options) 17 @repeat = repeat_from(options) 18 end
Public Instance Methods
call()
click to toggle source
# File lib/fixturama/changes/chain/return_action.rb 9 def call 10 @value 11 end
Private Instance Methods
repeat_from(options)
click to toggle source
# File lib/fixturama/changes/chain/return_action.rb 28 def repeat_from(options) 29 options.fetch(:repeat, 1).to_i.tap { |val| return val if val.positive? } 30 raise Fixturama::FixtureError.new("a number of repeats", options) 31 end
value_from(options)
click to toggle source
# File lib/fixturama/changes/chain/return_action.rb 20 def value_from(options) 21 value = options[:return] 22 value.respond_to?(:dup) ? value.dup : value 23 rescue TypeError 24 # in the Ruby 2.3.0 Fixnum#dup is defined, but raises TypeError 25 value 26 end