Class: Hackle::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/hackle/internal/workspace/workspace.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiments:, feature_flags:, buckets:, event_types:, segments:, containers:, parameter_configurations:, remote_config_parameters:) ⇒ Workspace

Returns a new instance of Workspace.

Parameters:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hackle/internal/workspace/workspace.rb', line 27

def initialize(
  experiments:,
  feature_flags:,
  buckets:,
  event_types:,
  segments:,
  containers:,
  parameter_configurations:,
  remote_config_parameters:
)
  # @type [Hash{Integer => Experiment}]
  @experiments = experiments

  # @type [Hash{Integer => Experiment}]
  @feature_flags = feature_flags

  # @type [Hash{Integer => Bucket}]
  @buckets = buckets

  # @type [Hash{String => EventType}]
  @event_types = event_types

  # @type [Hash{String => Segment}]
  @segments = segments

  # @type [Hash{Integer => Container}]
  @containers = containers

  # @type [Hash{Integer => ParameterConfiguration}]
  @parameter_configurations = parameter_configurations

  # @type [Hash{String => RemoteConfigParameter}]
  @remote_config_parameters = remote_config_parameters
end

Class Method Details

.create(experiments: [], feature_flags: [], buckets: [], event_types: [], segments: [], containers: [], parameter_configurations: [], remote_config_parameters: []) ⇒ Workspace

Parameters:

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/hackle/internal/workspace/workspace.rb', line 120

def create(
  experiments: [],
  feature_flags: [],
  buckets: [],
  event_types: [],
  segments: [],
  containers: [],
  parameter_configurations: [],
  remote_config_parameters: []
)
  Workspace.new(
    experiments: experiments.each_with_object({}) { |item, hash| hash[item.key] = item },
    feature_flags: feature_flags.each_with_object({}) { |item, hash| hash[item.key] = item },
    buckets: buckets.each_with_object({}) { |item, hash| hash[item.id] = item },
    event_types: event_types.each_with_object({}) { |item, hash| hash[item.key] = item },
    segments: segments.each_with_object({}) { |item, hash| hash[item.key] = item },
    containers: containers.each_with_object({}) { |item, hash| hash[item.id] = item },
    parameter_configurations: parameter_configurations.each_with_object({}) { |item, hash| hash[item.id] = item },
    remote_config_parameters: remote_config_parameters.each_with_object({}) { |item, hash| hash[item.key] = item }
  )
end

.from_hash(hash) ⇒ Hackle::Workspace

Parameters:

  • hash (Hash)

Returns:



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/hackle/internal/workspace/workspace.rb', line 144

def from_hash(hash)
  Workspace.create(
    experiments: hash[:experiments].map { |it| experiment(it, ExperimentType::AB_TEST) },
    feature_flags: hash[:featureFlags].map { |it| experiment(it, ExperimentType::FEATURE_FLAG) },
    buckets: hash[:buckets].map { |it| bucket(it) },
    event_types: hash[:events].map { |it| event_type(it) },
    segments: hash[:segments].map { |it| segment_or_nil(it) }.compact,
    containers: hash[:containers].map { |it| container(it) },
    parameter_configurations: hash[:parameterConfigurations].map { |it| parameter_configuration(it) },
    remote_config_parameters: hash[:remoteConfigParameters].map { |it| remote_config_parameter_or_nil(it) }.compact
  )
end

Instance Method Details

#get_bucket_or_nil(bucket_id) ⇒ Hackle::Bucket?

Parameters:

  • bucket_id (Integer)

Returns:



82
83
84
# File 'lib/hackle/internal/workspace/workspace.rb', line 82

def get_bucket_or_nil(bucket_id)
  @buckets[bucket_id]
end

#get_container_or_nil(container_id) ⇒ Hackle::Container?

Parameters:

  • container_id (Integer)

Returns:



94
95
96
# File 'lib/hackle/internal/workspace/workspace.rb', line 94

def get_container_or_nil(container_id)
  @containers[container_id]
end

#get_event_type_or_nil(event_type_key) ⇒ Hackle::EventType?

Parameters:

  • event_type_key (String)

Returns:



76
77
78
# File 'lib/hackle/internal/workspace/workspace.rb', line 76

def get_event_type_or_nil(event_type_key)
  @event_types[event_type_key]
end

#get_experiment_or_nil(experiment_key) ⇒ Hackle::Experiment?

Parameters:

  • experiment_key (Integer)

Returns:



64
65
66
# File 'lib/hackle/internal/workspace/workspace.rb', line 64

def get_experiment_or_nil(experiment_key)
  @experiments[experiment_key]
end

#get_feature_flag_or_nil(feature_key) ⇒ Hackle::Experiment?

Parameters:

  • feature_key (Integer)

Returns:



70
71
72
# File 'lib/hackle/internal/workspace/workspace.rb', line 70

def get_feature_flag_or_nil(feature_key)
  @feature_flags[feature_key]
end

#get_parameter_configuration_or_nil(parameter_configuration_id) ⇒ Hackle::ParameterConfiguration?

Parameters:

  • parameter_configuration_id (Integer)

Returns:



100
101
102
# File 'lib/hackle/internal/workspace/workspace.rb', line 100

def get_parameter_configuration_or_nil(parameter_configuration_id)
  @parameter_configurations[parameter_configuration_id]
end

#get_remote_config_parameter_or_nil(parameter_key) ⇒ Hackle::RemoteConfigParameter?

Parameters:

  • parameter_key (String)

Returns:



106
107
108
# File 'lib/hackle/internal/workspace/workspace.rb', line 106

def get_remote_config_parameter_or_nil(parameter_key)
  @remote_config_parameters[parameter_key]
end

#get_segment_or_nil(segment_key) ⇒ Hackle::Segment?

Parameters:

  • segment_key (String)

Returns:



88
89
90
# File 'lib/hackle/internal/workspace/workspace.rb', line 88

def get_segment_or_nil(segment_key)
  @segments[segment_key]
end