Class: Servactory::Context::Workspace::Internals

Inherits:
Object
  • Object
show all
Defined in:
lib/servactory/context/workspace/internals.rb

Instance Method Summary collapse

Constructor Details

#initialize(context:, collection_of_internals:) ⇒ Internals

Returns a new instance of Internals.



7
8
9
10
# File 'lib/servactory/context/workspace/internals.rb', line 7

def initialize(context:, collection_of_internals:)
  @context = context
  @collection_of_internals = collection_of_internals
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/servactory/context/workspace/internals.rb', line 24

def method_missing(name, *args)
  if name.to_s.end_with?("=")
    prepared_name = name.to_s.delete("=").to_sym

    assign_with(prepared_name:, value: args.pop) { raise_error_for(:assign, prepared_name) }
  else
    fetch_with(name:) { raise_error_for(:fetch, name) }
  end
end

Instance Method Details

#except(*names) ⇒ Object



18
19
20
21
22
# File 'lib/servactory/context/workspace/internals.rb', line 18

def except(*names)
  @collection_of_internals
    .except(*names)
    .to_h { |internal| [internal.name, send(internal.name)] }
end

#only(*names) ⇒ Object



12
13
14
15
16
# File 'lib/servactory/context/workspace/internals.rb', line 12

def only(*names)
  @collection_of_internals
    .only(*names)
    .to_h { |internal| [internal.name, send(internal.name)] }
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/servactory/context/workspace/internals.rb', line 34

def respond_to_missing?(name, *)
  @collection_of_internals.names.include?(name) || super
end