examples/group_dynamic_lookup.rb in flipper-0.20.4 vs examples/group_dynamic_lookup.rb in flipper-0.21.0.rc1

- old
+ new

@@ -1,35 +1,25 @@ -require File.expand_path('../example_setup', __FILE__) - +require 'bundler/setup' require 'flipper' -adapter = Flipper::Adapters::Memory.new -flipper = Flipper.new(adapter) -stats = flipper[:stats] +stats = Flipper[:stats] # Register group Flipper.register(:enabled_team_member) do |actor, context| combos = context.actors_value.map { |flipper_id| flipper_id.split(";", 2) } team_names = combos.select { |class_name, id| class_name == "Team" }.map { |class_name, id| id } teams = team_names.map { |name| Team.find(name) } teams.any? { |team| team.member?(actor) } end # Some class that represents actor that will be trying to do something -class User - attr_reader :id - - def initialize(id) - @id = id - end - - def flipper_id - "User;#{@id}" - end +class User < Struct.new(:id) + include Flipper::Identifier end class Team + include Flipper::Identifier attr_reader :name def self.all @all ||= {} end @@ -48,13 +38,9 @@ @name end def member?(actor) @members.map(&:id).include?(actor.id) - end - - def flipper_id - "Team:#{@name}" end end jnunemaker = User.new("jnunemaker") jbarnette = User.new("jbarnette")