Skip to content

Commit

Permalink
More clear name for groups registry internal stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Mar 26, 2015
1 parent 1811e64 commit 708a445
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions lib/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.new(adapter, options = {})
# Raises Flipper::DuplicateGroup if the group is already registered.
def self.register(name, &block)
group = Types::Group.new(name, &block)
groups.add(group.name, group)
groups_registry.add(group.name, group)
group
rescue Registry::DuplicateKey
raise DuplicateGroup, %Q{Group #{name.inspect} has already been registered}
Expand All @@ -34,14 +34,14 @@ def self.register(name, &block)
#
# Returns nothing.
def self.unregister_groups
groups.clear
groups_registry.clear
end

# Public: Check if a group exists
#
# Returns boolean
def self.group_exists?(name)
self.groups.key?(name)
groups_registry.key?(name)
end

# Internal: Fetches a group by name.
Expand All @@ -55,19 +55,19 @@ def self.group_exists?(name)
# Returns the Flipper::Group if group registered.
# Raises Flipper::GroupNotRegistered if group is not registered.
def self.group(name)
groups.get(name)
groups_registry.get(name)
rescue Flipper::Registry::KeyNotFound => e
raise GroupNotRegistered, "Group #{e.key.inspect} has not been registered"
end

# Internal: Registry of all groups.
def self.groups
@groups ||= Registry.new
# Internal: Registry of all groups_registry.
def self.groups_registry
@groups_registry ||= Registry.new
end

# Internal: Change the groups registry.
def self.groups=(registry)
@groups = registry
# Internal: Change the groups_registry registry.
def self.groups_registry=(registry)
@groups_registry = registry
end
end

Expand Down
18 changes: 9 additions & 9 deletions spec/flipper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@
end
end

describe ".groups" do
describe ".groups_registry" do
it "returns a registry instance" do
Flipper.groups.should be_instance_of(Flipper::Registry)
Flipper.groups_registry.should be_instance_of(Flipper::Registry)
end
end

describe ".groups=" do
it "sets groups registry" do
describe ".groups_registry=" do
it "sets groups_registry registry" do
registry = Flipper::Registry.new
Flipper.groups = registry
Flipper.instance_variable_get("@groups").should eq(registry)
Flipper.groups_registry = registry
Flipper.instance_variable_get("@groups_registry").should eq(registry)
end
end

describe ".register" do
it "adds a group to the group_registry" do
registry = Flipper::Registry.new
Flipper.groups = registry
Flipper.groups_registry = registry
group = Flipper.register(:admins) { |actor| actor.admin? }
registry.get(:admins).should eq(group)
end

it "adds a group to the group_registry for string name" do
registry = Flipper::Registry.new
Flipper.groups = registry
Flipper.groups_registry = registry
group = Flipper.register('admins') { |actor| actor.admin? }
registry.get(:admins).should eq(group)
end
Expand All @@ -59,7 +59,7 @@

describe ".unregister_groups" do
it "clear group registry" do
Flipper.groups.should_receive(:clear)
Flipper.groups_registry.should_receive(:clear)
Flipper.unregister_groups
end
end
Expand Down

0 comments on commit 708a445

Please sign in to comment.