Class: Autotype::InferenceMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/autotype/engine.rb

Defined Under Namespace

Classes: ConfigHashWiring, OutputEmitWiring, PortWiring

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(member_types: nil, ports: nil, config_options: nil, structured_owners: nil, referenced_types: nil, member_type_hints: {}, option_type_hints: {}, side_effect_methods: nil, structured_type_prefixes: [], port_wiring: nil, output_emit: nil, config_hash: nil, framework_self_fallbacks: {}, type_locators: []) ⇒ InferenceMetadata

Returns a new instance of InferenceMetadata.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/autotype/engine.rb', line 74

def initialize(
  member_types: nil,
  ports: nil,
  config_options: nil,
  structured_owners: nil,
  referenced_types: nil,
  member_type_hints: {},
  option_type_hints: {},
  side_effect_methods: nil,
  structured_type_prefixes: [],
  port_wiring: nil,
  output_emit: nil,
  config_hash: nil,
  framework_self_fallbacks: {},
  type_locators: []
)
  @member_types = member_types || Hash.new { |hash, key| hash[key] = {} }
  @ports = ports || Hash.new { |hash, key| hash[key] = { inputs: {}, outputs: {} } }
  @config_options = config_options || Hash.new { |hash, key| hash[key] = {} }
  @structured_owners = structured_owners || Set.new
  @referenced_types = referenced_types || Set.new
  @member_type_hints = member_type_hints
  @option_type_hints = option_type_hints
  @side_effect_methods = side_effect_methods || Set.new
  @structured_type_prefixes = structured_type_prefixes
  @port_wiring = port_wiring
  @output_emit = output_emit
  @config_hash = config_hash
  @framework_self_fallbacks = framework_self_fallbacks
  @type_locators = type_locators
end

Instance Attribute Details

#config_hashObject (readonly)

Returns the value of attribute config_hash.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def config_hash
  @config_hash
end

#config_optionsObject (readonly)

Returns the value of attribute config_options.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def config_options
  @config_options
end

#framework_self_fallbacksObject (readonly)

Returns the value of attribute framework_self_fallbacks.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def framework_self_fallbacks
  @framework_self_fallbacks
end

#member_type_hintsObject (readonly)

Returns the value of attribute member_type_hints.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def member_type_hints
  @member_type_hints
end

#member_typesObject (readonly)

Returns the value of attribute member_types.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def member_types
  @member_types
end

#option_type_hintsObject (readonly)

Returns the value of attribute option_type_hints.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def option_type_hints
  @option_type_hints
end

#output_emitObject (readonly)

Returns the value of attribute output_emit.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def output_emit
  @output_emit
end

#port_wiringObject (readonly)

Returns the value of attribute port_wiring.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def port_wiring
  @port_wiring
end

#portsObject (readonly)

Returns the value of attribute ports.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def ports
  @ports
end

#referenced_typesObject (readonly)

Returns the value of attribute referenced_types.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def referenced_types
  @referenced_types
end

#side_effect_methodsObject (readonly)

Returns the value of attribute side_effect_methods.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def side_effect_methods
  @side_effect_methods
end

#structured_ownersObject (readonly)

Returns the value of attribute structured_owners.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def structured_owners
  @structured_owners
end

#structured_type_prefixesObject (readonly)

Returns the value of attribute structured_type_prefixes.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def structured_type_prefixes
  @structured_type_prefixes
end

#type_locatorsObject (readonly)

Returns the value of attribute type_locators.



44
45
46
# File 'lib/autotype/engine.rb', line 44

def type_locators
  @type_locators
end

Class Method Details

.deep_copy_nested(source) ⇒ Object



64
65
66
# File 'lib/autotype/engine.rb', line 64

def self.deep_copy_nested(source)
  source.transform_values(&:dup)
end

.deep_copy_ports(source) ⇒ Object



68
69
70
71
72
# File 'lib/autotype/engine.rb', line 68

def self.deep_copy_ports(source)
  source.transform_values do |ports|
    { inputs: ports[:inputs].dup, outputs: ports[:outputs].dup }
  end
end

.emptyObject



49
50
51
# File 'lib/autotype/engine.rb', line 49

def self.empty
  new
end

.from_collector(collector, **overrides) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/autotype/engine.rb', line 53

def self.from_collector(collector, **overrides)
  new(
    member_types: deep_copy_nested(collector.declared_member_types),
    ports: deep_copy_ports(collector.declared_ports),
    config_options: deep_copy_nested(collector.declared_config_options),
    structured_owners: collector.structured_owners.dup,
    referenced_types: collector.referenced_types.dup,
    **overrides
  )
end

Instance Method Details

#config_hash?Boolean

Returns:

  • (Boolean)


124
# File 'lib/autotype/engine.rb', line 124

def config_hash? = @config_hash && @config_options.values.any?(&:any?)

#locate_type_file(type_name) ⇒ Object



133
134
135
# File 'lib/autotype/engine.rb', line 133

def locate_type_file(type_name)
  @type_locators.lazy.filter_map { |locator| locator.call(type_name) }.first
end

#merge_config_options!(source) ⇒ Object



118
119
120
# File 'lib/autotype/engine.rb', line 118

def merge_config_options!(source)
  source.each { |owner, options| @config_options[owner].merge!(options) }
end

#merge_member_types!(source) ⇒ Object



114
115
116
# File 'lib/autotype/engine.rb', line 114

def merge_member_types!(source)
  source.each { |owner, fields| @member_types[owner].merge!(fields) }
end

#merge_ports!(source) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/autotype/engine.rb', line 106

def merge_ports!(source)
  source.each do |owner, ports|
    @ports[owner] ||= { inputs: {}, outputs: {} }
    @ports[owner][:inputs].merge!(ports[:inputs])
    @ports[owner][:outputs].merge!(ports[:outputs])
  end
end

#output_emit?Boolean

Returns:

  • (Boolean)


123
# File 'lib/autotype/engine.rb', line 123

def output_emit? = @output_emit && @ports.values.any? { |ports| ports[:outputs].any? }

#port_wiring?Boolean

Returns:

  • (Boolean)


122
# File 'lib/autotype/engine.rb', line 122

def port_wiring? = @port_wiring && @ports.values.any? { |ports| ports[:inputs].any? }

#structured_type?(name) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
# File 'lib/autotype/engine.rb', line 126

def structured_type?(name)
  return true if @structured_owners.include?(name)
  return true if @member_types.key?(name) && @member_types[name].any?

  @structured_type_prefixes.any? { |prefix| name.start_with?(prefix) }
end