Class: Finitio::ProxyType

Inherits:
Type
  • Object
show all
Defined in:
lib/finitio/type/proxy_type.rb,
lib/finitio/generation/proxy_type.rb,
lib/finitio/json_schema/proxy_type.rb

Constant Summary

Constants included from Metadata

Metadata::EMPTY_METADATA

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#==, #anonymous?, #name, #name=, #named?, #suppremum, #to_s

Methods included from Metadata

#metadata, #metadata=, #metadata?

Constructor Details

#initialize(target_name, target = nil) ⇒ ProxyType

Returns a new instance of ProxyType.



4
5
6
7
8
9
10
11
# File 'lib/finitio/type/proxy_type.rb', line 4

def initialize(target_name, target = nil)
  unless target_name.is_a?(String)
    raise ArgumentError, "String expected for type name, got `#{target_name}`"
  end

  @target_name = target_name
  @target = target
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



12
13
14
# File 'lib/finitio/type/proxy_type.rb', line 12

def target
  @target
end

#target_nameObject (readonly)

Returns the value of attribute target_name.



12
13
14
# File 'lib/finitio/type/proxy_type.rb', line 12

def target_name
  @target_name
end

Instance Method Details

#bind!(system) ⇒ Object



30
31
32
33
34
# File 'lib/finitio/type/proxy_type.rb', line 30

def bind!(system)
  @target = system.fetch(target_name) {
    raise Error, "No such type `#{target_name}` in #{system}"
  }
end

#default_nameObject



14
15
16
# File 'lib/finitio/type/proxy_type.rb', line 14

def default_name
  "_#{target_name}_"
end

#dress(*args, &bl) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/finitio/type/proxy_type.rb', line 24

def dress(*args, &bl)
  raise Error, "Proxy not resolved: #{target_name}" unless @target

  @target.dress(*args, &bl)
end

#generate_data(*args, &bl) ⇒ Object



4
5
6
7
8
# File 'lib/finitio/generation/proxy_type.rb', line 4

def generate_data(*args, &bl)
  # Proxy type is supposed to be used only on recursive types
  # so we can't go further to avoid a infinite recursion
  {}
end

#include?(*args, &bl) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



18
19
20
21
22
# File 'lib/finitio/type/proxy_type.rb', line 18

def include?(*args, &bl)
  raise Error, "Proxy not resolved: #{target_name}" unless @target

  @target.include?(*args, &bl)
end

#resolve_proxies(system) ⇒ Object



36
37
38
39
40
# File 'lib/finitio/type/proxy_type.rb', line 36

def resolve_proxies(system)
  system.fetch(target_name) {
    raise Error, "No such type `#{target_name}` in #{system}"
  }
end

#to_json_schema(*args, &bl) ⇒ Object



4
5
6
7
8
9
# File 'lib/finitio/json_schema/proxy_type.rb', line 4

def to_json_schema(*args, &bl)
  # ProxyType is supposed to be used only for recursive types.
  # We don't have support for references yet, so let just
  # generate an object here in the mean time.
  { type: "object" }
end

#unconstrainedObject

Raises:



42
43
44
45
# File 'lib/finitio/type/proxy_type.rb', line 42

def unconstrained
  return @target.unconstrained if @target
  raise Error, "`unconstrained` cannot be call whithout proxies being resolved"
end