Sha256: d84d245c921d4c6ba55403c5ff69113cece92a3be9403b0c8d88591a30c9eeaa

Contents?: true

Size: 1.46 KB

Versions: 60

Compression:

Stored size: 1.46 KB

Contents

class Onceover
  class Class
    @@all = []

    attr_accessor :name

    def initialize(name)
      # if the class we are trying to create is a regex, create class objects
      # for everything that matches.
      if Onceover::Class.name_is_regexp?(name)
        expression = Onceover::Class.string_to_regexp(name)
        matched_classes = Onceover::Controlrepo.classes.keep_if { |c| c =~ expression }
        matched_classes.each do |c|
          Onceover::Class.new(c)
        end
      else
        @name = name
        @@all << self
      end
    end

    # This is what is executed to see if something exists as a class. The same
    # thing is executed for groups etc. when building up test matricies.
    def self.find(class_name)
      if Onceover::Class.name_is_regexp?(class_name)
        return @@all.select do |cls|
          cls.name =~ Onceover::Class.string_to_regexp(class_name)
        end
      else
        @@all.each do |cls|
          if cls.name == class_name
            return cls
          end
        end
      end
      logger.warn "Class #{class_name} not found"
      nil
    end

    def self.all
      @@all
    end

    def self.string_to_regexp(string)
      if Onceover::Class.name_is_regexp?(string)
        Regexp.new(string[1..-2])
      else
        raise "#{string} does not start and end with / and cannot be converted to regexp"
      end
    end

    def self.name_is_regexp?(name)
      name.start_with?('/') and name.end_with?('/')
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
onceover-4.0.0 lib/onceover/class.rb
onceover-3.22.0 lib/onceover/class.rb
onceover-3.21.0 lib/onceover/class.rb
onceover-3.20.0 lib/onceover/class.rb
onceover-3.19.2 lib/onceover/class.rb
onceover-3.19.1 lib/onceover/class.rb
onceover-3.19.0 lib/onceover/class.rb
onceover-3.18.1 lib/onceover/class.rb
onceover-3.18.0 lib/onceover/class.rb
onceover-3.17.3 lib/onceover/class.rb
onceover-3.17.2 lib/onceover/class.rb
onceover-3.17.1 lib/onceover/class.rb
onceover-3.17.0 lib/onceover/class.rb
onceover-3.16.0 lib/onceover/class.rb
onceover-3.15.2 lib/onceover/class.rb
onceover-3.15.1 lib/onceover/class.rb
onceover-3.15.0 lib/onceover/class.rb
onceover-3.14.1 lib/onceover/class.rb
onceover-3.14.0 lib/onceover/class.rb
onceover-3.13.4 lib/onceover/class.rb