Sha256: 868332bcd8d90ab93f85241de4a1e74d49c8cff04657e8c5f9cc4045465c86fe

Contents?: true

Size: 859 Bytes

Versions: 5

Compression:

Stored size: 859 Bytes

Contents

# frozen_string_literal: true

require "active_support"
require "active_support/core_ext"

module TrackBallast
  # A module for building callable service classes where exactly one method
  # will ever be called and only the return value of that method matters, not
  # the class instance itself.
  #
  # == Usage
  #
  # - Define +initialize+ with the desired arguments
  # - Define +call+ with the desired logic
  # - Extend the class with this module
  #
  # == Example
  #
  #     class DivideByTwo
  #       extend TrackBallast::Callable
  #
  #       def initialize(int)
  #         @int = int
  #       end
  #
  #       def call
  #         int / 2
  #       end
  #
  #       private
  #
  #       attr_reader :int
  #     end
  #
  #     DivideByTwo.call(10) # => 5
  module Callable
    def call(...)
      new(...).call { yield }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
track_ballast-0.2.0.beta1 lib/track_ballast/callable.rb
track_ballast-0.1.0 lib/track_ballast/callable.rb
track_ballast-0.1.0.beta6 lib/track_ballast/callable.rb
track_ballast-0.1.0.beta5 lib/track_ballast/callable.rb
track_ballast-0.1.0.beta4 lib/track_ballast/callable.rb