Class: Hackle::Workspace
- Inherits:
-
Object
- Object
- Hackle::Workspace
- Defined in:
- lib/hackle/internal/workspace/workspace.rb
Class Method Summary collapse
- .create(experiments: [], feature_flags: [], buckets: [], event_types: [], segments: [], containers: [], parameter_configurations: [], remote_config_parameters: []) ⇒ Workspace
- .from_hash(hash) ⇒ Hackle::Workspace
Instance Method Summary collapse
- #get_bucket_or_nil(bucket_id) ⇒ Hackle::Bucket?
- #get_container_or_nil(container_id) ⇒ Hackle::Container?
- #get_event_type_or_nil(event_type_key) ⇒ Hackle::EventType?
- #get_experiment_or_nil(experiment_key) ⇒ Hackle::Experiment?
- #get_feature_flag_or_nil(feature_key) ⇒ Hackle::Experiment?
- #get_parameter_configuration_or_nil(parameter_configuration_id) ⇒ Hackle::ParameterConfiguration?
- #get_remote_config_parameter_or_nil(parameter_key) ⇒ Hackle::RemoteConfigParameter?
- #get_segment_or_nil(segment_key) ⇒ Hackle::Segment?
-
#initialize(experiments:, feature_flags:, buckets:, event_types:, segments:, containers:, parameter_configurations:, remote_config_parameters:) ⇒ Workspace
constructor
A new instance of Workspace.
Constructor Details
#initialize(experiments:, feature_flags:, buckets:, event_types:, segments:, containers:, parameter_configurations:, remote_config_parameters:) ⇒ Workspace
Returns a new instance of Workspace.
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
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
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?
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?
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?
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?
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?
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?
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?
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?
88 89 90 |
# File 'lib/hackle/internal/workspace/workspace.rb', line 88 def get_segment_or_nil(segment_key) @segments[segment_key] end |