Sha256: 6688a2740b75cfcf565e1aa0bf61e74afa04e4c9fa50bd9d7b906e8e3d786382

Contents?: true

Size: 1.57 KB

Versions: 457

Compression:

Stored size: 1.57 KB

Contents

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

457 entries across 457 versions & 2 rubygems

Version Path
fastlane-2.22.0.beta.20170321010023 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0.beta.20170320010043 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0.beta.20170319010027 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0.beta.20170318010107 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0.beta.20170317010039 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.21.0.beta.20170316010039 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170315010053 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170314010029 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170313010048 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170312010035 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170311010030 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170310010058 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170309010049 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170308010036 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.19.3 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170307010029 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.19.2 fastlane_core/lib/fastlane_core/feature/feature.rb
fastlane-2.20.0.beta.20170306010752 fastlane_core/lib/fastlane_core/feature/feature.rb