Module: Flipper::Adapter

Overview

Adding a module include so we have some hooks for stuff down the road

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/flipper/adapter.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#default_configObject

Public: Default config for a feature’s gate values.



64
65
66
# File 'lib/flipper/adapter.rb', line 64

def default_config
  self.class.default_config
end

#export(format: :json, version: 1) ⇒ Object

Public: Exports the adapter in a given format for a given format version.

Returns a Flipper::Export instance.



59
60
61
# File 'lib/flipper/adapter.rb', line 59

def export(format: :json, version: 1)
  Flipper::Exporter.build(format: format, version: version).call(self)
end

#get_allObject

Public: Get all features and gate values in one call. Defaults to one call to features and another to get_multi. Feel free to override per adapter to make this more efficient.



30
31
32
33
# File 'lib/flipper/adapter.rb', line 30

def get_all
  instances = features.map { |key| Flipper::Feature.new(key, self) }
  get_multi(instances)
end

#get_multi(features) ⇒ Object

Public: Get multiple features in one call. Defaults to one get per feature. Feel free to override per adapter to make this more efficient and reduce network calls.



38
39
40
41
42
43
44
# File 'lib/flipper/adapter.rb', line 38

def get_multi(features)
  result = {}
  features.each do |feature|
    result[feature.key] = get(feature)
  end
  result
end

#import(source) ⇒ Object

Public: Ensure that adapter is in sync with source adapter provided.

source - The source dsl, adapter or export to import.

Returns true if successful.



51
52
53
54
# File 'lib/flipper/adapter.rb', line 51

def import(source)
  Adapters::Sync::Synchronizer.new(self, self.class.from(source), raise: true).call
  true
end

#nameObject

Public: default name of the adapter



69
70
71
# File 'lib/flipper/adapter.rb', line 69

def name
  @name ||= self.class.name.split('::').last.split(/(?=[A-Z])/).join('_').downcase.to_sym
end