Class: FeatureHub::Sdk::FeatureHubRepository

Inherits:
InternalFeatureRepository show all
Defined in:
lib/feature_hub/sdk/feature_repository.rb

Overview

the core implementation of a feature repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apply_features = nil) ⇒ FeatureHubRepository

Returns a new instance of FeatureHubRepository.



9
10
11
12
13
14
15
# File 'lib/feature_hub/sdk/feature_repository.rb', line 9

def initialize(apply_features = nil)
  super()
  @strategy_matcher = apply_features || FeatureHub::Sdk::Impl::ApplyFeature.new
  @interceptors = []
  @features = {}
  @ready = false
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



7
8
9
# File 'lib/feature_hub/sdk/feature_repository.rb', line 7

def features
  @features
end

Instance Method Details

#apply(strategies, key, feature_id, context) ⇒ Object



17
18
19
# File 'lib/feature_hub/sdk/feature_repository.rb', line 17

def apply(strategies, key, feature_id, context)
  @strategy_matcher.apply(strategies, key, feature_id, context)
end

#extract_feature_stateObject



64
65
66
67
68
# File 'lib/feature_hub/sdk/feature_repository.rb', line 64

def extract_feature_state
  @features.values
           .filter(&:exists?)
           .map(&:feature_state)
end

#feature(key) ⇒ Object



43
44
45
46
# File 'lib/feature_hub/sdk/feature_repository.rb', line 43

def feature(key)
  sym_key = key.to_sym
  @features[sym_key] || make_feature_holder(sym_key)
end

#find_interceptor(feature_value) ⇒ Object



52
53
54
# File 'lib/feature_hub/sdk/feature_repository.rb', line 52

def find_interceptor(feature_value)
  @interceptors.filter_map { |interceptor| interceptor.intercepted_value(feature_value) }.first
end

#not_ready!Object



60
61
62
# File 'lib/feature_hub/sdk/feature_repository.rb', line 60

def not_ready!
  @ready = false
end

#notify(status, data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/feature_hub/sdk/feature_repository.rb', line 21

def notify(status, data)
  return unless status

  if status.to_sym == :failed
    @ready = false
    return
  end

  return if data.nil?

  case status.to_sym
  when :features
    update_features(data)
    @ready = true
  when :feature
    update_feature(data)
    @ready = true
  when :delete_feature
    delete_feature(data)
  end
end

#ready?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/feature_hub/sdk/feature_repository.rb', line 56

def ready?
  @ready
end

#register_interceptor(interceptor) ⇒ Object



48
49
50
# File 'lib/feature_hub/sdk/feature_repository.rb', line 48

def register_interceptor(interceptor)
  @interceptors.push(interceptor)
end