Class: Shipeasy::Client
- Inherits:
-
Object
- Object
- Shipeasy::Client
- Defined in:
- lib/shipeasy/client.rb
Overview
A lightweight, user-bound evaluation handle. Construct one per user/request via its real constructor:
flags = Shipeasy::Client.new(current_user)
flags.get_flag("new_checkout") # NO user arg — bound at construction
flags.get_experiment("price_test", { price: 9 })
It is cheap: it delegates every evaluation to the single global engine built by ‘Shipeasy.configure { … }`. It does NOT open its own HTTP connection, fetch, or start a poll timer.
The configured ‘attributes` transform (see Shipeasy::Configuration#attributes) runs ONCE here, in the constructor, against the raw user object you pass. The resulting attribute hash is then enriched with the request-scoped anonymous_id (when you supplied neither user_id nor anonymous_id) and bound, so every getter reads the same bag.
Raises if constructed before ‘Shipeasy.configure` registered an engine.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The resolved attribute hash this handle evaluates against.
Instance Method Summary collapse
-
#get_config(name, decode = nil, default: nil) ⇒ Object
Configs are not user-scoped, but exposed here for one-stop ergonomics.
- #get_experiment(name, default_params, decode = nil) ⇒ Object
- #get_flag(name, default: false) ⇒ Object
- #get_flag_detail(name) ⇒ Object
-
#get_killswitch(name, switch_key = nil) ⇒ Object
Killswitches are not user-scoped; forwarded straight to the engine.
-
#initialize(user) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(user) ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/shipeasy/client.rb', line 24 def initialize(user) engine = Shipeasy.engine if engine.nil? raise Error, "Shipeasy::Client.new(user) called before Shipeasy.configure " \ "{ |c| c.api_key = … }. Call Shipeasy.configure once at app boot." end @engine = engine # Run the configured attributes transform (default identity), then apply # the existing anon-id merge exactly as the per-call engine path does. mapped = Shipeasy.attributes_transform.call(user) @attributes = engine.bind_attributes(mapped) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
The resolved attribute hash this handle evaluates against.
22 23 24 |
# File 'lib/shipeasy/client.rb', line 22 def attributes @attributes end |
Instance Method Details
#get_config(name, decode = nil, default: nil) ⇒ Object
Configs are not user-scoped, but exposed here for one-stop ergonomics.
46 47 48 |
# File 'lib/shipeasy/client.rb', line 46 def get_config(name, decode = nil, default: nil) @engine.get_config(name, decode, default: default) end |
#get_experiment(name, default_params, decode = nil) ⇒ Object
50 51 52 |
# File 'lib/shipeasy/client.rb', line 50 def get_experiment(name, default_params, decode = nil) @engine.get_experiment(name, @attributes, default_params, decode) end |
#get_flag(name, default: false) ⇒ Object
37 38 39 |
# File 'lib/shipeasy/client.rb', line 37 def get_flag(name, default: false) @engine.get_flag(name, @attributes, default: default) end |
#get_flag_detail(name) ⇒ Object
41 42 43 |
# File 'lib/shipeasy/client.rb', line 41 def get_flag_detail(name) @engine.get_flag_detail(name, @attributes) end |
#get_killswitch(name, switch_key = nil) ⇒ Object
Killswitches are not user-scoped; forwarded straight to the engine.
55 56 57 |
# File 'lib/shipeasy/client.rb', line 55 def get_killswitch(name, switch_key = nil) @engine.get_killswitch(name, switch_key) end |