Sha256: 05b706d794fe88bf53553dc9bcc24deaff3edf5fa9ceb7332afa54fe5c5882cf

Contents?: true

Size: 901 Bytes

Versions: 16

Compression:

Stored size: 901 Bytes

Contents

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

require 'flipper'

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

16 entries across 16 versions & 1 rubygems

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