<commit_before># frozen_string_literal: true

module PaidUp
  # PaidUp Plan model
  class Plan < ActiveRecord::Base
    has_many(
      :plan_feature_settings,
      class_name: 'PaidUp::PlanFeatureSetting',
      foreign_key: 'paid_up_plan_id',
      inverse_of: :plan
    )
    accepts_nested_attributes_for :plan_feature_settings

    after_initialize :load_stripe_data
    after_save :expire_stripe_data

    attr_accessor :stripe_data

    validates_presence_of :title, :stripe_id
    validates_uniqueness_of :title

    default_scope { order('sort_order ASC') }
    scope :subscribable, -> { where('sort_order >=  ?', 0) }
    scope :within, ->(ids) { where(id: ids) }
    scope :without, ->(ids) { where.not(id: ids) }
    scope :free, (lambda do
      find_by_stripe_id(PaidUp.configuration.free_plan_stripe_id)
    end)
    scope :display, (lambda do |within, without|
      plans = subscribable
      plans = plans.within(within) if within.present?
      plans = plans.without(without) if without.present?
      plans
    end)

    def reload(*args, &blk)
      super(*args, &blk)
      load_stripe_data
      self
    end

    def feature_setting(feature_name)
      feature = PaidUp::Feature.find_by_slug!(feature_name)<commit_msg>Renamed scopes :within and :without to avoid naming conflict with ActiveStorage<commit_after># frozen_string_literal: true

module PaidUp
  # PaidUp Plan model
  class Plan < ActiveRecord::Base
    has_many(
      :plan_feature_settings,
      class_name: 'PaidUp::PlanFeatureSetting',
      foreign_key: 'paid_up_plan_id',
      inverse_of: :plan
    )
    accepts_nested_attributes_for :plan_feature_settings

    after_initialize :load_stripe_data
    after_save :expire_stripe_data

    attr_accessor :stripe_data

    validates_presence_of :title, :stripe_id
    validates_uniqueness_of :title

    default_scope { order('sort_order ASC') }
    scope :subscribable, -> { where('sort_order >=  ?', 0) }
    scope :including, ->(ids) { where(id: ids) }
    scope :excluding, ->(ids) { where.not(id: ids) }
    scope :free, (lambda do
      find_by_stripe_id(PaidUp.configuration.free_plan_stripe_id)
    end)
    scope :display, (lambda do |including, excluding|
      plans = subscribable
      plans = plans.including(including) if including.present?
      plans = plans.excluding(excluding) if excluding.present?
      plans
    end)

    def reload(*args, &blk)
      super(*args, &blk)
      load_stripe_data
      self
    end

    def feature_setting(feature_name)
      feature = PaidUp::Feature.find_by_slug!(feature_name)
{'fraction_non_alphanumeric': 0.09623593325572372, 'fraction_numerical': 0.0007760962359332557, 'mean_word_length': 3.530755711775044, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707977', 'n_tokens_mistral': 869, 'n_tokens_neox': 847, 'n_words': 179}