Class: DuckTyper::InterfaceSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/duck_typer/interface_setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects, namespace:, type:, methods:, strict:, name:, minimum: 0) ⇒ InterfaceSetup

Returns a new instance of InterfaceSetup.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/duck_typer/interface_setup.rb', line 9

def initialize(objects, namespace:, type:, methods:, strict:, name:, minimum: 0)
  raise ArgumentError, "cannot specify both objects and namespace" if objects && namespace
  raise ArgumentError, "objects or namespace is required" if objects.nil? && namespace.nil?

  @objects = resolve_objects(objects, namespace)
  raise ArgumentError, "at least #{minimum} object(s) required" if @objects.size < minimum

  name ||= namespace&.name
  @name = name
  @strict = strict
  @checker = InterfaceChecker.new(type:, methods:, strict:, name:)
end

Instance Attribute Details

#checkerObject (readonly)

Returns the value of attribute checker.



7
8
9
# File 'lib/duck_typer/interface_setup.rb', line 7

def checker
  @checker
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/duck_typer/interface_setup.rb', line 7

def name
  @name
end

#objectsObject (readonly)

Returns the value of attribute objects.



7
8
9
# File 'lib/duck_typer/interface_setup.rb', line 7

def objects
  @objects
end

#strictObject (readonly)

Returns the value of attribute strict.



7
8
9
# File 'lib/duck_typer/interface_setup.rb', line 7

def strict
  @strict
end