Sha256: 92790b9b42e26f4ca9addefc055e20a7473da1ef563e4b3b75a938836a9bb24f

Contents?: true

Size: 935 Bytes

Versions: 43

Compression:

Stored size: 935 Bytes

Contents

require File.expand_path('../example_setup', __FILE__)

require 'flipper'
require 'flipper/adapters/memory'

adapter = Flipper::Adapters::Memory.new
flipper = Flipper.new(adapter)
stats = flipper[:stats]

# Register group
Flipper.register(:admins) do |actor|
  actor.respond_to?(:admin?) && actor.admin?
end

# Some class that represents actor that will be trying to do something
class User
  attr_reader :id

  def initialize(id, admin)
    @id = id
    @admin = admin
  end

  # Must respond to flipper_id
  alias_method :flipper_id, :id

  def admin?
    @admin == true
  end
end

admin = User.new(1, true)
non_admin = User.new(2, false)

puts "Stats for admin: #{stats.enabled?(admin)}"
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"

puts "\nEnabling Stats for admins...\n\n"
stats.enable(flipper.group(:admins))

puts "Stats for admin: #{stats.enabled?(admin)}"
puts "Stats for non_admin: #{stats.enabled?(non_admin)}"

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
flipper-0.15.0 examples/group.rb
flipper-0.14.0 examples/group.rb
flipper-0.13.0 examples/group.rb
flipper-0.13.0.beta1 examples/group.rb
flipper-0.12.2 examples/group.rb
flipper-0.12.1 examples/group.rb
flipper-0.12.0 examples/group.rb
flipper-0.11.0 examples/group.rb
flipper-0.11.0.rc1 examples/group.rb
flipper-0.11.0.beta9 examples/group.rb
flipper-0.11.0.beta8 examples/group.rb
flipper-0.11.0.beta7 examples/group.rb
flipper-0.11.0.beta6 examples/group.rb
flipper-0.11.0.beta5 examples/group.rb
flipper-0.11.0.beta4 examples/group.rb
flipper-0.11.0.beta3 examples/group.rb
flipper-0.11.0.beta1 examples/group.rb
flipper-0.10.2 examples/group.rb
flipper-0.10.1 examples/group.rb
flipper-0.10.0 examples/group.rb