Sha256: bffe37c797e5e7aa5ac02016511fd6977dbd3f48aed0785548f436bd6749bfa1

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

module Workarea
  class Segment
    module LifeCycle
      extend ActiveSupport::Concern

      included do
        field :_id, type: String, default: -> { self.class.instance_id }
        cattr_accessor :default_rules
      end

      class_methods do
        def model_name
          Segment.model_name
        end

        def instance
          first || create!(rules: default_rules)
        end

        def instance_id
          name.demodulize.underscore.to_sym
        end
      end

      def self.create!
        [
          FirstTimeVisitor,
          ReturningVisitor,
          FirstTimeCustomer,
          ReturningCustomer,
          LoyalCustomer
        ].each(&:instance)
      end

      def name
        self.class.name.demodulize.underscore.titleize
      end

      def destroy
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-core-3.5.0.beta.1 app/models/workarea/segment/life_cycle.rb