summaryrefslogtreecommitdiff
path: root/lib/feature.rb
blob: b89e5176a08a03b7b6b33c2c2b5d975f627349c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'flipper/adapters/active_record'

class Feature
  # Classes to override flipper table names
  class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature
    # Using `self.table_name` won't work. ActiveRecord bug?
    superclass.table_name = 'features'
  end

  class FlipperGate < Flipper::Adapters::ActiveRecord::Gate
    superclass.table_name = 'feature_gates'
  end

  class << self
    def all
      flipper.features.to_a
    end

    def get(key)
      flipper.feature(key)
    end

    private

    def flipper
      @flipper ||= begin
        adapter = Flipper::Adapters::ActiveRecord.new(
          feature_class: FlipperFeature, gate_class: FlipperGate)

        Flipper.new(adapter)
      end
    end
  end
end