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-3.13.3 lib/onceover/class.rb
onceover-3.13.2 lib/onceover/class.rb
onceover-3.13.1 lib/onceover/class.rb
onceover-3.13.0 lib/onceover/class.rb
onceover-3.12.5 lib/onceover/class.rb
onceover-3.12.4 lib/onceover/class.rb
onceover-3.12.3 lib/onceover/class.rb
onceover-3.12.2 lib/onceover/class.rb
onceover-3.12.1 lib/onceover/class.rb
onceover-3.12.0 lib/onceover/class.rb
onceover-3.11.1 lib/onceover/class.rb
onceover-3.11.0 lib/onceover/class.rb
onceover-3.10.2 lib/onceover/class.rb
onceover-3.10.1 lib/onceover/class.rb
onceover-3.10.0 lib/onceover/class.rb
onceover-3.9.0 lib/onceover/class.rb
onceover-3.8.0 lib/onceover/class.rb
onceover-3.7.0 lib/onceover/class.rb
onceover-3.6.2 lib/onceover/class.rb
onceover-3.6.1 lib/onceover/class.rb