Module: Foobara::CommandPatternImplementation::Concerns::Reflection::ClassMethods

Defined in:
foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb

Instance Method Summary collapse

Instance Method Details

#allObject



14
15
16
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 14

def all
  @all ||= []
end

#command_nameObject



89
90
91
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 89

def command_name
  Util.non_full_name(self)
end

#errors_types_depended_onObject



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 167

def errors_types_depended_on
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?

  if defined?(@errors_types_depended_on) && @errors_types_depended_on.key?(remove_sensitive)
    return @errors_types_depended_on[remove_sensitive]
  end

  @errors_types_depended_on ||= {}
  @errors_types_depended_on[remove_sensitive] = begin
    error_classes = possible_errors.map(&:error_class)
    error_classes.map(&:types_depended_on).inject(:|) || Set.new
  end
end

#foobara_manifestObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 22

def foobara_manifest
  to_include = TypeDeclarations.foobara_manifest_context_to_include

  depends_on = self.depends_on.map do |command_name|
    other_command = Foobara::Namespace.global.foobara_lookup!(command_name,
                                                              mode: Foobara::Namespace::LookupMode::ABSOLUTE)
    if to_include
      to_include << other_command
    end
    other_command.foobara_manifest_reference
  end.sort

  types = types_depended_on.map do |t|
    if to_include
      to_include << t
    end
    t.foobara_manifest_reference
  end.sort

  inputs_types_depended_on = self.inputs_types_depended_on.map do |t|
    if to_include
      to_include << t
    end
    t.foobara_manifest_reference
  end.sort

  result_types_depended_on = self.result_types_depended_on.map do |t|
    if to_include
      to_include << t
    end
    t.foobara_manifest_reference
  end.sort

  errors_types_depended_on = self.errors_types_depended_on.map do |t|
    if to_include
      to_include << t
    end
    t.foobara_manifest_reference
  end.sort

  possible_errors = self.possible_errors.map do |possible_error|
    [possible_error.key.to_s, possible_error.foobara_manifest]
  end.sort.to_h

  h = Util.remove_blank(
    types_depended_on: types,
    inputs_types_depended_on:,
    result_types_depended_on:,
    errors_types_depended_on:,
    possible_errors:,
    depends_on:,
    # TODO: allow inputs type to be nil or really any type?
    inputs_type: inputs_type&.reference_or_declaration_data || {
      type: "::attributes",
      element_type_declarations: {},
      required: []
    }
  ).merge(description:)

  if result_type
    # TODO: find a way to represent literal types like "nil"
    h[:result_type] = result_type.reference_or_declaration_data
  end

  super.merge(h)
end

#inputs_types_depended_onObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 121

def inputs_types_depended_on
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?

  if defined?(@inputs_types_depended_on) && @inputs_types_depended_on.key?(remove_sensitive)
    return @inputs_types_depended_on[remove_sensitive]
  end

  @inputs_types_depended_on ||= {}
  @inputs_types_depended_on[remove_sensitive] = if inputs_type
                                                  if inputs_type.registered?
                                                    # TODO: if we ever change from attributes-only inputs type
                                                    # then this will be handy
                                                    # :nocov:
                                                    if !remove_sensitive || !inputs_type.sensitive?
                                                      Set[inputs_type]
                                                    else
                                                      Set.new
                                                    end
                                                    # :nocov:
                                                  else
                                                    inputs_type.types_depended_on
                                                  end
                                                else
                                                  Set.new
                                                end
end

#reset_allObject



18
19
20
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 18

def reset_all
  remove_instance_variable("@all") if instance_variable_defined?("@all")
end

#result_types_depended_onObject



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 148

def result_types_depended_on
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?

  if defined?(@result_types_depended_on) && @result_types_depended_on.key?(remove_sensitive)
    return @result_types_depended_on[remove_sensitive]
  end

  @result_types_depended_on ||= {}
  @result_types_depended_on[remove_sensitive] = if result_type
                                                  if result_type.registered?
                                                    Set[result_type]
                                                  else
                                                    result_type.types_depended_on
                                                  end
                                                else
                                                  Set.new
                                                end
end

#types_depended_onObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/reflection.rb', line 93

def types_depended_on
  remove_sensitive = TypeDeclarations.foobara_manifest_context_remove_sensitive?

  if defined?(@types_depended_on) && @types_depended_on.key?(remove_sensitive)
    return @types_depended_on[remove_sensitive]
  end

  @types_depended_on ||= {}
  @types_depended_on[remove_sensitive] = begin
    types = inputs_types_depended_on |
            result_types_depended_on |
            errors_types_depended_on

    unless depends_on_entities.empty?
      entity_types = depends_on_entities.map(&:entity_type)

      if remove_sensitive
        entity_types = entity_types.reject(&:sensitive?)
      end

      types |= entity_types
      types |= entity_types.map(&:types_depended_on).inject(:|)
    end

    types
  end
end