Sha256: 42684a8c350d667ea53787c86f854090bbf7d528bb14d20393b6d975b18e95c3

Contents?: true

Size: 1.6 KB

Versions: 660

Compression:

Stored size: 1.6 KB

Contents

require_relative '../env'

module FastlaneCore
  class Feature
    class << self
      attr_reader :features

      def register(env_var: nil, description: nil)
        feature = self.new(description: description, env_var: env_var)
        @features[feature.env_var] = feature
      end

      def enabled?(env_var)
        feature = @features[env_var]
        return false if feature.nil?
        return FastlaneCore::Env.truthy?(feature.env_var)
      end

      def register_class_method(klass: nil, symbol: nil, disabled_symbol: nil, enabled_symbol: nil, env_var: nil)
        return if klass.nil? || symbol.nil? || disabled_symbol.nil? || enabled_symbol.nil? || env_var.nil?
        klass.define_singleton_method(symbol) do |*args|
          if Feature.enabled?(env_var)
            klass.send(enabled_symbol, *args)
          else
            klass.send(disabled_symbol, *args)
          end
        end
      end

      def register_instance_method(klass: nil, symbol: nil, disabled_symbol: nil, enabled_symbol: nil, env_var: nil)
        return if klass.nil? || symbol.nil? || disabled_symbol.nil? || enabled_symbol.nil? || env_var.nil?
        klass.send(:define_method, symbol.to_s) do |*args|
          if Feature.enabled?(env_var)
            send(enabled_symbol, *args)
          else
            send(disabled_symbol, *args)
          end
        end
      end
    end

    @features = {}

    attr_reader :env_var, :description
    def initialize(env_var: nil, description: nil)
      raise "Invalid Feature" if env_var.nil? || description.nil?
      @env_var = env_var
      @description = description
    end
  end
end

Version data entries

660 entries across 660 versions & 5 rubygems

Version Path
fastlane-2.225.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.224.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.223.1 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.223.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.222.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.221.1 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.221.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.220.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.219.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.218.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-security-patched-2.216.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.217.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.216.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.215.1 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.215.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-mercafacil-2.214.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.214.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.213.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.212.2 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane_pricing_fix-2.212.1 fastlane_core/lib/fastlane_core/feature/feature.rb