Class: ConvenientService::Support::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/support/arguments.rb,
lib/convenient_service/support/arguments/exceptions.rb,
lib/convenient_service/support/arguments/null_arguments.rb

Direct Known Subclasses

NullArguments

Defined Under Namespace

Modules: Exceptions Classes: NullArguments

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ void

Parameters:

  • args (Array<Object>)
  • kwargs (Hash{Symbol => Object})
  • block (Proc, nil)


38
39
40
41
42
# File 'lib/convenient_service/support/arguments.rb', line 38

def initialize(*args, **kwargs, &block)
  @args = args
  @kwargs = kwargs
  @block = block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



18
19
20
# File 'lib/convenient_service/support/arguments.rb', line 18

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



30
31
32
# File 'lib/convenient_service/support/arguments.rb', line 30

def block
  @block
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



24
25
26
# File 'lib/convenient_service/support/arguments.rb', line 24

def kwargs
  @kwargs
end

Class Method Details

.null_argumentsConvenientService::Support::Arguments::NullArguments



48
49
50
# File 'lib/convenient_service/support/arguments.rb', line 48

def null_arguments
  @null_arguments ||= Support::Arguments::NullArguments.new
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
105
# File 'lib/convenient_service/support/arguments.rb', line 97

def ==(other)
  return unless other.instance_of?(self.class)

  return false if args != other.args
  return false if kwargs != other.kwargs
  return false if block != other.block

  true
end

#[](key) ⇒ Object

Returns Can be any type.

Parameters:

  • key (Integer, Symbol)

Returns:

  • (Object)

    Can be any type.



85
86
87
88
89
90
91
# File 'lib/convenient_service/support/arguments.rb', line 85

def [](key)
  case key
  when Integer then args[key]
  when Symbol then kwargs[key]
  else ::ConvenientService.raise Exceptions::InvalidKeyType.new(key: key)
  end
end

#any?Booleam

Returns:

  • (Booleam)


63
64
65
66
67
68
69
# File 'lib/convenient_service/support/arguments.rb', line 63

def any?
  return true if args.any?
  return true if kwargs.any?
  return true if block

  false
end

#deconstructArray

Note:

Expected to be called only from pattern matching. Avoid direct usage of this method.

Returns:

  • (Array)


114
115
116
# File 'lib/convenient_service/support/arguments.rb', line 114

def deconstruct
  [args, kwargs, block]
end

#deconstruct_keys(keys) ⇒ Hash

Note:

Expected to be called only from pattern matching. Avoid direct usage of this method.

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/convenient_service/support/arguments.rb', line 126

def deconstruct_keys(keys)
  keys ||= [:args, :kwargs, :block]

  keys.each_with_object({}) do |key, hash|
    case key
    when :args
      hash[key] = args
    when :kwargs
      hash[key] = kwargs
    when :block
      hash[key] = block
    end
  end
end

#none?Booleam

Returns:

  • (Booleam)


74
75
76
# File 'lib/convenient_service/support/arguments.rb', line 74

def none?
  !any?
end

#null_arguments?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/convenient_service/support/arguments.rb', line 56

def null_arguments?
  false
end