Class: Codependent::Validators::ValueValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/codependent/validators/value_validator.rb

Constant Summary collapse

SINGLETON_ERROR =
'Value injectables are only allowed on singletons.'.freeze
NIL_VALUE_ERROR =
'Value injectables must not be nil.'.freeze
NO_DEPENDENCIES_ERROR =
'Value injectables may not have dependencies'.freeze

Instance Method Summary collapse

Instance Method Details

#call(type, state, dependencies) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
# File 'lib/codependent/validators/value_validator.rb', line 8

def call(type, state, dependencies)
  raise SINGLETON_ERROR unless type == :singleton
  raise NIL_VALUE_ERROR unless state[:value]

  no_dependencies = !dependencies || dependencies.count != 0

  raise NO_DEPENDENCIES_ERROR if no_dependencies
end