Sha256: 503438afeb4c89e14e44f34cb4d62bc145b91356f838bb236269d80a8a6ab00d
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
module SPNet # Provides a means to get/set a parameter value in a Block object. # # @author James Tunnell class ParamInPort < InPort include Hashmake::HashMakeable # Define arg specs to use in processing hashed arguments during #initialize. ARG_SPECS = { :limiter => arg_spec(:reqd => false, :type => Limiter, :default => ->(){ NoLimiter.new } ), :get_value_handler => arg_spec(:reqd => true, :type => Proc, :validator => ->(p){ p.arity == 0 }), :set_value_handler => arg_spec(:reqd => true, :type => Proc, :validator => ->(p){ p.arity == 1 }) } attr_reader :limiter # A new instance of ParamInPort. # @param [Hash] hashed_args Hashed arguments for initialization. See Network::ARG_SPECS # for details. def initialize hashed_args = {} hash_make hashed_args, ParamInPort::ARG_SPECS @skip_limiting = @limiter.is_a?(NoLimiter) super(:matching_class => ParamOutPort) end # Set the parameter to the given value. def set_value value unless @skip_limiting value = @limiter.apply_limit value, get_value end @set_value_handler.call value end # Get the parameter's current value. def get_value @get_value_handler.call end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spnet-0.1.8 | lib/spnet/ports/param_in_port.rb |