Sha256: 390c266385b258c5b84135ba68c1cff6dbe7241cf48c4bb0e955f90f5904aeea

Contents?: true

Size: 891 Bytes

Versions: 5

Compression:

Stored size: 891 Bytes

Contents

module Tito
  module Eventable

    def self.included(base)
      base.extend ClassMethods
      base.class_eval do
        property :event
        property :event_id
      end
    end

    def event=(tito_event)
      self.event_id = tito_event.id
      self.attributes[:event] = tito_event
      @event = tito_event
    end

    module ClassMethods
      def path(params=nil)
        prefix_path = '%{account_id}/%{event_id}'
        path_params = params.delete(:path) || params
        path_params[:event_id] = params[:event][:id]
        path_params[:account_id] = params[:event][:account_id] || params[:event]['account-id']
        parts = [].unshift(prefix_path % path_params.symbolize_keys)
        parts << params[:type]
        File.join(*parts)
        rescue KeyError
          raise ArgumentError, "Please make sure to include account_id and event_id"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tito-0.1.8 lib/tito/eventable.rb
tito-0.1.7 lib/tito/eventable.rb
tito-0.1.6 lib/tito/eventable.rb
tito-0.1.4 lib/tito/eventable.rb
tito-0.1.3 lib/tito/eventable.rb