Class: Onceover::Class

Inherits:
Object
  • Object
show all
Defined in:
lib/onceover/class.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Class

Returns a new instance of Class.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/onceover/class.rb', line 7

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/onceover/class.rb', line 5

def name
  @name
end

Class Method Details

.allObject



40
41
42
# File 'lib/onceover/class.rb', line 40

def self.all
  @@all
end

.find(class_name) ⇒ Object

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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/onceover/class.rb', line 24

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

.name_is_regexp?(name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/onceover/class.rb', line 52

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

.string_to_regexp(string) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/onceover/class.rb', line 44

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