class VexillaClient

Public Class Methods

new(environment, base_url, custom_instance_hash) click to toggle source
# File lib/vexilla_client.rb, line 9
def initialize(environment, base_url, custom_instance_hash)
  @environment = environment
  @base_url = base_url
  @custom_instance_hash = custom_instance_hash
end

Public Instance Methods

fetch_flags(file_name) click to toggle source
# File lib/vexilla_client.rb, line 15
def fetch_flags(file_name)
  response = HTTParty.get("#{@base_url}/#{file_name}")
  parsed_response = JSON.parse(response.body)
  parsed_response["environments"]
end
set_flags(flags) click to toggle source
# File lib/vexilla_client.rb, line 21
def set_flags(flags)
  @flags = flags
end
should(feature_name) click to toggle source
# File lib/vexilla_client.rb, line 25
def should(feature_name)
  feature = @flags[@environment]["untagged"][feature_name]

  if feature["type"] == @@VEXILLA_FEATURE_TYPE_TOGGLE then
    feature["value"]
  elsif feature["type"] == @@VEXILLA_FEATURE_TYPE_GRADUAL
    hash_value = hash_instance_id(feature["seed"])
    hash_value <= feature["value"]
  else
    false
  end
end

Private Instance Methods

hash_instance_id(seed) click to toggle source
# File lib/vexilla_client.rb, line 40
def hash_instance_id(seed)
  chars = @custom_instance_hash.chars

  total = chars.map { |char| char.ord }.reduce(0) { |sum, char_code| sum + char_code }

  (total * seed * 42.0) % 100
end