Sha256: 581eccaaedc65c68563a499556460c5b84044bcaa7524a5ae9bfb911fc42af66

Contents?: true

Size: 374 Bytes

Versions: 6

Compression:

Stored size: 374 Bytes

Contents

module Ahoy
  module Model
    def visitable(name = :visit, **options)
      class_eval do
        belongs_to(name, class_name: "Ahoy::Visit", optional: true, **options)
        before_create :set_ahoy_visit
      end
      class_eval %{
        def set_ahoy_visit
          self.#{name} ||= Thread.current[:ahoy].try(:visit_or_create)
        end
      }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ahoy_matey-3.0.5 lib/ahoy/model.rb
ahoy_matey-3.0.4 lib/ahoy/model.rb
ahoy_matey-3.0.3 lib/ahoy/model.rb
ahoy_matey-3.0.2 lib/ahoy/model.rb
ahoy_matey-3.0.1 lib/ahoy/model.rb
ahoy_matey-3.0.0 lib/ahoy/model.rb