Sha256: 3c74fca3c343dc96f953dc14e2c30cc1ffc5afe08de85c2fe53c5543312e4275

Contents?: true

Size: 412 Bytes

Versions: 9

Compression:

Stored size: 412 Bytes

Contents

# frozen_string_literal: true

module ActionTracker
  class RecordsCollection < Array
    def select_by(path, value)
      keys = path.to_s.split('.').map(&:to_sym)

      items = select do |item|
        item.dig(*keys) == value
      end

      self.class.new items
    end

    def last_event
      last.dig(:payload, :event)
    end

    def last_content
      last.dig(:payload, :content)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
action_tracker_client-0.1.8 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.7 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.6 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.5 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.4 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.3 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.2 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.1 lib/action_tracker/utils/records_collection.rb
action_tracker_client-0.1.0 lib/action_tracker/utils/records_collection.rb