Sha256: c41ed8f2a85923ececb416ab9e795d856ac52ce8b60529e8f2cb0baea9400e65

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module FeatureGate
  class GatedFeature < ActiveRecord::Base
    self.table_name = 'feature_gate_gated_features'

    validates :name, presence: true
    validates :gated, inclusion: { in: [true, false] }

    scope :opened, -> { where(gated: false) }
    scope :closed, -> { where(gated: true) }
    scope :stale, -> { where('updated_at != created_at and updated_at < ?', Time.zone.now - FeatureGate.configuration.time_to_stale) }

    def deploy_feature!
      self.gated = false
      save!
    end

    def gate_feature!
      self.gated = true
      save!
    end

    def status
      if gated
        'closed'
      else
        'opened'
      end
    end

    def destroyable?
      regex = /FeatureGate::Manager.gate(\(|\s)('|")#{name}('|")|FeatureGate::Manager.gate_page(\(|\s)('|")#{name}('|")/
      files = Dir["#{Dir.pwd}/app/views/**/*.html.erb"] + Dir["#{Dir.pwd}/app/controllers/**/*.rb"]

      files.each do |file|
        f = File.new(file)
        text = f.read
        return false if text =~ regex
      end

      true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
feature_gate-0.2.6 app/models/feature_gate/gated_feature.rb
feature_gate-0.2.5 app/models/feature_gate/gated_feature.rb
feature_gate-0.2.4 app/models/feature_gate/gated_feature.rb