Sha256: 1a41efd15f04b915cb9be453f1e4f2d695ea32efa5287737f8dc9bffea0d5177

Contents?: true

Size: 619 Bytes

Versions: 2

Compression:

Stored size: 619 Bytes

Contents

module JsonApiClient
  module Helpers
    module Initializable
      extend ActiveSupport::Concern

      included do
        class_attribute :initializers
        self.initializers = []
      end

      module ClassMethods
        def initializer(method = nil, &block)
          self.initializers.push(method || block)
        end
      end

      def initialize(params = {})
        initializers.each do |initializer|
          if initializer.respond_to?(:call)
            initializer.call(self, params)
          else
            self.send(initializer, params)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_api_client-1.0.0.beta3 lib/json_api_client/helpers/initializable.rb
json_api_client-1.0.0.beta2 lib/json_api_client/helpers/initializable.rb