Sha256: 11b0253936a8d69faed9ff4656747927d1a7d9a87dbe279996286900565ba26f

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'activity_engine/activity_data_structure'
require 'activity_engine/exceptions'
module ActivityEngine
  class ActivityBuilder

    attr_accessor :configuration_proc, :activity_receiver
    private :activity_receiver=, :configuration_proc=

    def initialize(activity_receiver, configuration_proc)
      unless activity_receiver.respond_to?(:call)
        raise RuntimeError, "Excpected :activity_receiver #{activity_receiver.inspect} to be callable"
      end
      unless configuration_proc.respond_to?(:call)
        raise RuntimeError, "Excpected :configuration_proc #{configuration_proc.inspect} to be callable"
      end
      self.activity_receiver = activity_receiver
      self.configuration_proc = configuration_proc
    end

    def call(context)
      configuration_proc.call(self, context)
      activity_receiver.call(self.to_activity_data_structure)
    end

    def to_activity_data_structure
      ActivityDataStructure.new.tap {|ads|
        ads.subject = subject
        ads.current_user = current_user
        ads.message = message
        ads.activity_type = activity_type
      }
    end

    attr_accessor :current_user, :message, :activity_type, :subject
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activity_engine-0.0.9 lib/activity_engine/activity_builder.rb
activity_engine-0.0.8 lib/activity_engine/activity_builder.rb
activity_engine-0.0.7 lib/activity_engine/activity_builder.rb
activity_engine-0.0.6 lib/activity_engine/activity_builder.rb
activity_engine-0.0.5 lib/activity_engine/activity_builder.rb