Class: Makitoo::FeatureFlag::Client
- Inherits:
-
Object
- Object
- Makitoo::FeatureFlag::Client
- Defined in:
- lib/makitoo/feature_flag.rb
Instance Method Summary collapse
- #init_segment(segment_id, user_or_id) ⇒ Object
-
#initialize(application_id, options = {}) ⇒ Client
constructor
A new instance of Client.
- #is_active(feature_name, user_or_id, default_state = false) ⇒ Object
- #success(feature_name, user_or_id) ⇒ Object
- #track(event_name, user_or_id, properties = {}) ⇒ Object
Constructor Details
#initialize(application_id, options = {}) ⇒ Client
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/makitoo/feature_flag.rb', line 13 def initialize(application_id, = {}) @logger = if .has_key?(:logger) [:logger] elsif defined?(Rails) Rails.logger else logger = Logger.new STDOUT logger.progname = 'Makitoo::FeatureFlag' logger end @logger.debug 'Initializing makitoo feature flag' @application_id = application_id @server = if .has_key?(:server) [:server] elsif [:ssl] 'https://features.makitoo.com/api/v1' else 'http://features.makitoo.com/api/v1' end @cache = [:cache] || MemoryCache.new(@logger) @environment_name = [:environment_name] || 'production' @concurrency = [:concurrency] || 1 @force_sync = [:force_sync] || @concurrency < 1 start_background_threads @logger.debug 'Makitoo initialized' end |
Instance Method Details
#init_segment(segment_id, user_or_id) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/makitoo/feature_flag.rb', line 71 def init_segment(segment_id, user_or_id) @logger.debug 'Start init_segment' post_json(@server + '/associate-foreign-id', { foreignId: segment_id, source: 'segment.com', installationId: User.of(user_or_id).id }) @logger.debug 'Stop init_segment' end |
#is_active(feature_name, user_or_id, default_state = false) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/makitoo/feature_flag.rb', line 40 def is_active(feature_name, user_or_id, default_state = false) @logger.debug 'Start is_active' user = User.of(user_or_id) feature_configuration = get_feature_configuration(feature_name, user) is_visible = if feature_configuration.nil? default_state else feature_configuration[:state] == 'ON' end event = if is_visible create_seen_event(feature_name, user) else create_skip_event(feature_name, user) end send_event(event) @logger.debug 'Stop is_active' is_visible end |
#success(feature_name, user_or_id) ⇒ Object
59 60 61 62 63 |
# File 'lib/makitoo/feature_flag.rb', line 59 def success(feature_name, user_or_id) @logger.debug 'Start is_active' send_event(create_success_event(feature_name, User.of(user_or_id))) @logger.debug 'Stop success' end |
#track(event_name, user_or_id, properties = {}) ⇒ Object
65 66 67 68 69 |
# File 'lib/makitoo/feature_flag.rb', line 65 def track(event_name, user_or_id, properties = {}) @logger.debug 'Start is_active' send_event(create_track_event(event_name, User.of(user_or_id), properties)) @logger.debug 'Stop track' end |