Skip to content

Commit

Permalink
Merge pull request #15 from Flagsmith/release/3.0.1
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
matthewelwell authored Jun 9, 2022
2 parents bb951c8 + 9aceedb commit 74c3cad
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 76 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
flagsmith (3.0.0)
flagsmith (3.0.1)
faraday
faraday-retry
faraday_middleware
Expand Down Expand Up @@ -29,8 +29,8 @@ GEM
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
Expand All @@ -40,7 +40,7 @@ GEM
faraday (~> 1.0)
gem-release (2.2.0)
method_source (1.0.0)
multipart-post (2.1.1)
multipart-post (2.2.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
Expand Down
4 changes: 1 addition & 3 deletions example/config/initializers/flagsmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
enable_local_evaluation: true,
environment_refresh_interval_seconds: 60,
default_flag_handler: lambda { |feature_name|
Flagsmith::Flag.new(
feature_name: feature_name, enabled: false, value: {}.to_json, feature_id: nil
)
Flagsmith::Flags::DefaultFlag.new(enabled: false, value: {}.to_json)
}
)
3 changes: 1 addition & 2 deletions lib/flagsmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
require 'flagsmith/sdk/errors'
require 'flagsmith/sdk/intervals'
require 'flagsmith/sdk/pooling_manager'
require 'flagsmith/sdk/models/flag'
require 'flagsmith/sdk/models/flags/collection'
require 'flagsmith/sdk/models/flags'
require 'flagsmith/sdk/instance_methods'

require 'flagsmith/engine/core'
Expand Down
62 changes: 0 additions & 62 deletions lib/flagsmith/sdk/models/flag.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,79 @@ module Flagsmith
module Flags
class NotFound < StandardError; end

# Flag Collection
class BaseFlag
include Comparable

attr_reader :enabled, :value, :default

def initialize(enabled:, value:, default:)
@enabled = enabled
@value = value
@default = default
end

def enabled?
enabled
end

alias is_default default
end

class DefaultFlag < BaseFlag
def initialize(enabled:, value:)
super(enabled: enabled, value: value, default: true)
end
end

class Flag < BaseFlag

attr_reader :feature_name, :feature_id

def initialize(feature_name:, enabled:, value:, feature_id:)
super(enabled: enabled, value: value, default: false)
@feature_name = feature_name
@feature_id = feature_id
end

def <=>(other)
feature_name <=> other.feature_name
end

def [](key)
to_h[key]
end

def to_h
{
feature_id: feature_id,
feature_name: feature_name,
value: value,
enabled: enabled,
default: default
}
end

class << self
def from_feature_state_model(feature_state_model, identity_id)
new(
enabled: feature_state_model.enabled,
value: feature_state_model.get_value(identity_id),
feature_name: feature_state_model.feature.name,
feature_id: feature_state_model.feature.id
)
end

def from_api(json_flag_data)
new(
enabled: json_flag_data[:enabled],
value: json_flag_data[:feature_state_value] || json_flag_data[:value],
feature_name: json_flag_data.dig(:feature, :name),
feature_id: json_flag_data.dig(:feature, :id)
)
end
end
end

class Collection
include Enumerable

Expand Down Expand Up @@ -75,7 +147,7 @@ class << self
def from_api(json_data, **args)
to_flag_object = lambda { |json_flag, acc|
acc[normalize_key(json_flag.dig(:feature, :name))] =
Flagsmith::Flag.from_api(json_flag)
Flagsmith::Flags::Flag.from_api(json_flag)
}

new(
Expand All @@ -87,7 +159,7 @@ def from_api(json_data, **args)
def from_feature_state_models(feature_states, identity_id: nil, **args)
to_flag_object = lambda { |feature_state, acc|
acc[normalize_key(feature_state.feature.name)] =
Flagsmith::Flag.from_feature_state_model(feature_state, identity_id)
Flagsmith::Flags::Flag.from_feature_state_model(feature_state, identity_id)
}

new(
Expand Down
2 changes: 1 addition & 1 deletion lib/flagsmith/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Flagsmith
VERSION = '3.0.0'
VERSION = '3.0.1'
end
2 changes: 1 addition & 1 deletion spec/engine-test-data

0 comments on commit 74c3cad

Please sign in to comment.