Module: Tardigrade::Dependency::ClassMethods

Defined in:
lib/tardigrade/dependency.rb

Instance Method Summary collapse

Instance Method Details

#argument_namesObject



25
26
27
# File 'lib/tardigrade/dependency.rb', line 25

def argument_names
  @argument_names || []
end

#with(*argument_names) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tardigrade/dependency.rb', line 8

def with(*argument_names)
  @argument_names = argument_names

  if argument_names.size > 0
    define_method(:initialize) do |**args|
      argument_names.each do |arg_name|
        unless args.keys.include?(arg_name)
          raise ArgumentError.new("argument :#{arg_name} missing")
        end

        instance_variable_set(:"@#{arg_name}", args[arg_name])
        self.class.attr_reader :"#{arg_name}"
      end
    end
  end
end