Class: SplitIoClient::SplitManager

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/managers/split_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, config = {}, adapter = nil, splits_repository = nil) ⇒ SplitIoManager

Creates a new split manager instance that connects to split.io API.

Parameters:

  • api_key (String)

    the API key for your split account



9
10
11
12
13
14
# File 'lib/splitclient-rb/managers/split_manager.rb', line 9

def initialize(api_key, config = {}, adapter = nil, splits_repository = nil)
  @localhost_mode_features = []
  @config = config
  @splits_repository = splits_repository
  @adapter = adapter
end

Instance Method Details

#build_split_view(name, split) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/splitclient-rb/managers/split_manager.rb', line 56

def build_split_view(name, split)
  return {} unless split

  treatments =
    if split[:conditions] && split[:conditions][0][:partitions]
      split[:conditions][0][:partitions].map { |partition| partition[:treatment] }
    else
      []
    end

    {
      name: name,
      traffic_type_name: split[:trafficTypeName],
      killed: split[:killed],
      treatments: treatments,
      change_number: split[:changeNumber]
    }
end

#split(split_name) ⇒ Object

method to get a split view



46
47
48
49
50
51
52
53
54
# File 'lib/splitclient-rb/managers/split_manager.rb', line 46

def split(split_name)
  return unless @splits_repository
  
  split = @splits_repository.get_split(split_name)

  return if split.nil? || Engine::Models::Split.archived?(split)

  build_split_view(split_name, split)
end

#split_namesObject

method to get the list of just split names. Ideal for ietrating and calling client.get_treatment



36
37
38
39
40
# File 'lib/splitclient-rb/managers/split_manager.rb', line 36

def split_names
  return if @splits_repository.nil?

  @splits_repository.split_names
end

#splitsObject

method to get the split list from the client



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/splitclient-rb/managers/split_manager.rb', line 20

def splits
  return if @splits_repository.nil?

  @splits_repository.splits.each_with_object([]) do |(name, split), memo|
    split_view = build_split_view(name, split)

    next if split_view[:name] == nil

    memo << split_view unless Engine::Models::Split.archived?(split)
  end
end