require 'pp' require 'pathname' require 'logger' root_path = Pathname(__FILE__).dirname.join('..').expand_path lib_path = root_path.join('lib') $:.unshift(lib_path) require 'active_record' ActiveRecord::Base.establish_connection({ adapter: 'sqlite3', database: ':memory:', }) require 'generators/flipper/templates/migration' CreateFlipperTables.up require 'flipper/adapters/active_record' adapter = Flipper::Adapters::ActiveRecord.new 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 rows in features table' pp Flipper::Adapters::ActiveRecord::Feature.all # [#, # #] puts puts 'all rows in gates table' pp Flipper::Adapters::ActiveRecord::Gate.all # [#, # #, # #, # #, # #, # #, # #, # #, # #] puts puts 'flipper get of feature' pp adapter.get(flipper[:stats]) # flipper get of feature