Sha256: 0d50f02bd38495776a36b8bb9d68f803556c6b3f88480ad5370d01fac491ee5c

Contents?: true

Size: 1.62 KB

Versions: 31

Compression:

Stored size: 1.62 KB

Contents

require 'pp'
require 'pathname'
require 'logger'

root_path = Pathname(__FILE__).dirname.join('..').expand_path
lib_path  = root_path.join('lib')
$:.unshift(lib_path)

require 'flipper/adapters/mongo'
Mongo::Logger.logger.level = Logger::INFO
collection = Mongo::Client.new(["127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"], :database => 'testing')['flipper']
adapter = Flipper::Adapters::Mongo.new(collection)
flipper = Flipper.new(adapter)

# Register a few groups.
Flipper.register(:admins) { |thing| thing.admin? }
Flipper.register(:early_access) { |thing| thing.early_access? }

# Create a user class that has flipper_id instance method.
User = Struct.new(:flipper_id)

flipper[:stats].enable
flipper[:stats].enable_group :admins
flipper[:stats].enable_group :early_access
flipper[:stats].enable_actor User.new('25')
flipper[:stats].enable_actor User.new('90')
flipper[:stats].enable_actor User.new('180')
flipper[:stats].enable_percentage_of_time 15
flipper[:stats].enable_percentage_of_actors 45

flipper[:search].enable

puts 'all docs in collection'
pp collection.find.to_a
# all docs in collection
# [{"_id"=>"stats",
#   "actors"=>["25", "90", "180"],
#   "boolean"=>"true",
#   "groups"=>["admins", "early_access"],
#   "percentage_of_actors"=>"45",
#   "percentage_of_time"=>"15"},
#  {"_id"=>"flipper_features", "features"=>["stats", "search"]},
#  {"_id"=>"search", "boolean"=>"true"}]
puts

puts 'flipper get of feature'
pp adapter.get(flipper[:stats])
# flipper get of feature
# {:boolean=>"true",
#  :groups=>#<Set: {"admins", "early_access"}>,
#  :actors=>#<Set: {"25", "90", "180"}>,
#  :percentage_of_actors=>"45",
#  :percentage_of_time=>"15"}

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
flipper-mongo-0.20.4 examples/mongo/internals.rb
flipper-mongo-0.20.3 examples/mongo/internals.rb
flipper-mongo-0.20.2 examples/mongo/internals.rb
flipper-mongo-0.20.1 examples/mongo/internals.rb
flipper-mongo-0.20.0 examples/mongo/internals.rb
flipper-mongo-0.20.0.beta3 examples/mongo/internals.rb
flipper-mongo-0.20.0.beta2 examples/mongo/internals.rb
flipper-mongo-0.20.0.beta1 examples/mongo/internals.rb
flipper-mongo-0.19.1 examples/mongo/internals.rb
flipper-mongo-0.19.0 examples/mongo/internals.rb
flipper-mongo-0.18.0 examples/mongo/internals.rb
flipper-mongo-0.17.2 examples/mongo/internals.rb
flipper-mongo-0.17.1 examples/mongo/internals.rb
flipper-mongo-0.16.2 examples/mongo/internals.rb
flipper-mongo-0.16.1 examples/mongo/internals.rb
flipper-mongo-0.16.0 examples/mongo/internals.rb
flipper-mongo-0.15.0 examples/mongo/internals.rb
flipper-mongo-0.14.0 examples/mongo/internals.rb
flipper-mongo-0.13.0 examples/mongo/internals.rb
flipper-mongo-0.13.0.beta1 examples/mongo/internals.rb