lib/pears.rb in pears-0.2.0 vs lib/pears.rb in pears-0.3.0

- old
+ new

@@ -2,10 +2,11 @@ require 'dry-configurable' require_relative "pears/version" require_relative "pears/errors" require_relative "pears/provider" require_relative "pears/subject" +require_relative "pears/commands" module Pears extend Dry::Configurable setting :redis_host, default: :localhost @@ -14,12 +15,16 @@ @subjects ||= [] end # This is the main way of locating a subject. def self.subject(name) - subjects + if subjects.any? { |sub| sub.name == name } + raise Pears::Error.new("subject name #{name} is already in use.") + end + Subject.new(name).tap do |subject| builder = Provider::Builder.new(subject) - @subjects << yield(builder) + yield(builder) + @subjects.push subject end end end