Skip to content

Instantly share code, notes, and snippets.

@synth
Created February 14, 2024 06:33
Show Gist options
  • Select an option

  • Save synth/8c9eee23aa9df535aa42a30f7cff9ba9 to your computer and use it in GitHub Desktop.

Select an option

Save synth/8c9eee23aa9df535aa42a30f7cff9ba9 to your computer and use it in GitHub Desktop.

Revisions

  1. synth created this gist Feb 14, 2024.
    30 changes: 30 additions & 0 deletions flag_registration.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    module Flipper
    module FlagRegistration
    # These functions are all memoized because they should be static for the
    # lifetime of a deployment (albeit they are really static to a Ruby process)
    def self.registered_flags
    @registered_flags ||= YAML.load_file("config/feature_flags.yml")
    end

    def self.flags_in_code
    @flags_in_code ||= begin
    search_regex = 'Flipper.enabled\?\(.*\)'
    command = "grep -rohE --exclude-dir='.//.*' --include='*rb' '#{search_regex}' ./"
    results = `#{command}`
    lines = results.split("\n")
    lines.map do |line|
    ast = Parser::CurrentRuby.parse(line)
    ast.children[2].children[0]
    end
    end
    end

    def self.registered_flags_not_found
    @registered_flags_not_found ||= flags_in_code - registered_flags.keys.map(&:to_sym)
    end

    def self.flags_not_registered
    @flags_not_registered ||= flags_in_code - registered_flags.keys.map(&:to_sym)
    end
    end
    end