Sha256: 5cbf5aacf679ac00e98c92deef759713920eac974f364303a68de2ee06e20027

Contents?: true

Size: 618 Bytes

Versions: 25

Compression:

Stored size: 618 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

25 entries across 25 versions & 1 rubygems

Version Path
json_api_client-0.2.1 lib/json_api_client/helpers/initializable.rb
json_api_client-0.2.0 lib/json_api_client/helpers/initializable.rb
json_api_client-0.1.3 lib/json_api_client/helpers/initializable.rb
json_api_client-0.1.2 lib/json_api_client/helpers/initializable.rb
json_api_client-0.1.1 lib/json_api_client/helpers/initializable.rb