Browse Source

Add plain_tags to Set and fix << to actually work.

Douglas Thrift 10 years ago
parent
commit
72d1c96b5e
4 changed files with 19 additions and 3 deletions
  1. 11 1
      lib/machine_tag/set.rb
  2. 4 2
      lib/machine_tag/tag.rb
  3. 2 0
      spec/machine_tag_set_spec.rb
  4. 2 0
      spec/machine_tag_tag_spec.rb

+ 11 - 1
lib/machine_tag/set.rb

@@ -27,9 +27,15 @@ module MachineTag
   # Set of tags which can be machine tags.
   #
   class Set < ::Set
+    # The tags in the set which are not machine tags
+    #
+    # @return [::Set<Tag>] the tags in the set which are not machine tags
+    #
+    attr_reader :plain_tags
+
     # The tags in the set which are machine tags
     #
-    # @return [::Set<Tag>] the tags in the set whihc are machine tags
+    # @return [::Set<Tag>] the tags in the set which are machine tags
     #
     attr_reader :machine_tags
 
@@ -40,6 +46,7 @@ module MachineTag
     # @param block [Proc] the optional block to preprocess elements before inserting them
     #
     def initialize(enum = nil, &block)
+      @plain_tags = ::Set.new
       @machine_tags = ::Set.new
       @tags_by_namespace = {}
       @tags_by_namespace_and_predicate = {}
@@ -62,10 +69,13 @@ module MachineTag
         @tags_by_namespace[tag.namespace] << tag
         @tags_by_namespace_and_predicate[tag.namespace_and_predicate] ||= ::Set.new
         @tags_by_namespace_and_predicate[tag.namespace_and_predicate] << tag
+      else
+        @plain_tags << tag
       end
 
       self
     end
+    alias_method :<<, :add
 
     # Retrieves machine tags in the Set with a matching namespace or namespace and predicate.
     #

+ 4 - 2
lib/machine_tag/tag.rb

@@ -24,7 +24,8 @@
 module MachineTag
   # The regular expression for matching the individual namespace and predicate portions of a machine tag
   #
-  # @return [Regexp] the regular expression for matching the individual namespace and predicate portions of a machine tag
+  # @return [Regexp] the regular expression for matching the individual namespace and predicate
+  #   portions of a machine tag
   #
   PREFIX = /[a-z][a-z0-9_]*/i
 
@@ -57,7 +58,8 @@ module MachineTag
 
     # The namespace and predicate portion of the machine tag, +nil+ if the tag is not a machine tag
     #
-    # @return [String, nil] the namespace and predicate portion of the machine tag, +nil+ if the tag is not a machine tag
+    # @return [String, nil] the namespace and predicate portion of the machine tag, +nil+ if the tag
+    #   is not a machine tag
     #
     attr_reader :namespace_and_predicate
 

+ 2 - 0
spec/machine_tag_set_spec.rb

@@ -0,0 +1,2 @@
+require 'spec_helper'
+

+ 2 - 0
spec/machine_tag_tag_spec.rb

@@ -0,0 +1,2 @@
+require 'spec_helper'
+