Class: YamlNormalizer::Services::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_normalizer/services/base.rb

Overview

The Base Service provides a convenience class method “call” to initialize the Service with the given arguments and call the method “call” on the instance.

Examples:

class ReverseService < Base
  def initialize(str)
    @str = str.to_s
  end

  def call
    @str.reverse
  end
end

Direct Known Subclasses

Check, IsYaml, Normalize

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Creates a service object. Inherit from Base and implement this method.

Examples:

class IsFile < Base
  attr_reader :file
  def initialize(file)
    @file = file.to_s
  end
  def call
    File.file? file
  end
end

Parameters:

  • *args (Array<Object>)

    arguments

Raises:

  • (NotImplementedError)

    if call is not implemented



34
35
36
# File 'lib/yaml_normalizer/services/base.rb', line 34

def initialize(*args)
  @args = args
end

Class Method Details

.call(*args) ⇒ Object

A convenience class method to initialize Normalize with the given arguments and call the method “call” on the instance.

Parameters:

  • *args (Array)

    arguments to be passed to Base.new



41
42
43
# File 'lib/yaml_normalizer/services/base.rb', line 41

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject

Inherit from Base and implement the call method

Raises:

  • (NotImplementedError)

    if call is not implemented



47
48
49
# File 'lib/yaml_normalizer/services/base.rb', line 47

def call
  raise NotImplementedError
end