module Typedeaf::ClassMethods
Public Instance Methods
__typedeaf_method_parameters__()
click to toggle source
# File lib/typedeaf/classmethods.rb, line 70 def __typedeaf_method_parameters__ if @__typedeaf_method_parameters__.nil? @__typedeaf_method_parameters__ = {} end return @__typedeaf_method_parameters__ end
default(value, *types)
click to toggle source
# File lib/typedeaf/classmethods.rb, line 8 def default(value, *types) return Typedeaf::Arguments::DefaultArgument.new(value, *types) end
define(method_sym, params={}, &block)
click to toggle source
# File lib/typedeaf/classmethods.rb, line 41 def define(method_sym, params={}, &block) params = params.freeze __typedeaf_validate_body_for(method_sym, block) __typedeaf_method_parameters__[method_sym] = params define_method(method_sym) do |*args, &blk| # Optimization, if we're a parameter-less method, just pass right # through without any checks whatsoever if params.empty? return instance_exec(&block) end __typedeaf_handle_nested_block(params, args, blk) __typedeaf_handle_default_parameters(params, args) __typedeaf_validate_positionals(params, args) __typedeaf_varstack__ << [method_sym, __typedeaf_validate_types(params, args)] begin instance_exec(&block) ensure __typedeaf_varstack__.pop end end return self end
future(method_sym, params={}, primitive=Concurrent::Future, &block)
click to toggle source
# File lib/typedeaf/classmethods.rb, line 16 def future(method_sym, params={}, primitive=Concurrent::Future, &block) __typedeaf_validate_body_for(method_sym, block) __typedeaf_method_parameters__[method_sym] = params define_method(method_sym) do |*args, &blk| __typedeaf_handle_nested_block(params, args, blk) __typedeaf_handle_default_parameters(params, args) __typedeaf_validate_positionals(params, args) stack_element = [method_sym, __typedeaf_validate_types(params, args)] primitive.new do # We're inserting into the varstack within the future to make sure # we're using the right thread+instance combination __typedeaf_varstack__ << stack_element begin instance_exec(&block) ensure __typedeaf_varstack__.pop end end.execute end return self end
promise(method_sym, params={}, &block)
click to toggle source
# File lib/typedeaf/classmethods.rb, line 12 def promise(method_sym, params={}, &block) future(method_sym, params, primitive=Concurrent::Promise, &block) end
Private Instance Methods
__typedeaf_validate_body_for(method, block)
click to toggle source
# File lib/typedeaf/classmethods.rb, line 80 def __typedeaf_validate_body_for(method, block) if block.nil? raise MissingMethodException, "You must provide a block for the #{method} body" end end