Class: DirectoryOfClasses
- Inherits:
-
Object
- Object
- DirectoryOfClasses
- Defined in:
- lib/quality/directory_of_classes.rb
Overview
Represents a source directory full of classe - e.g., lib/vincelifedaily/checks/*
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
Instance Method Summary collapse
- #basenames ⇒ Object
- #basenames_without_extension ⇒ Object
- #filenames ⇒ Object
-
#initialize(dir: raise, class_suffix: '', module_name: '') ⇒ DirectoryOfClasses
constructor
A new instance of DirectoryOfClasses.
- #require_classes ⇒ Object
- #symbols_and_classes ⇒ Object
Constructor Details
#initialize(dir: raise, class_suffix: '', module_name: '') ⇒ DirectoryOfClasses
Returns a new instance of DirectoryOfClasses.
10 11 12 13 14 |
# File 'lib/quality/directory_of_classes.rb', line 10 def initialize(dir: raise, class_suffix: '', module_name: '') @dir = dir @class_suffix = class_suffix @module_name = module_name end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
8 9 10 |
# File 'lib/quality/directory_of_classes.rb', line 8 def dir @dir end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
8 9 10 |
# File 'lib/quality/directory_of_classes.rb', line 8 def module_name @module_name end |
Instance Method Details
#basenames ⇒ Object
20 21 22 |
# File 'lib/quality/directory_of_classes.rb', line 20 def basenames filenames.map { |filename| File.basename(filename) } end |
#basenames_without_extension ⇒ Object
24 25 26 |
# File 'lib/quality/directory_of_classes.rb', line 24 def basenames_without_extension filenames.map { |filename| File.basename(filename, '.*') } end |
#filenames ⇒ Object
16 17 18 |
# File 'lib/quality/directory_of_classes.rb', line 16 def filenames Dir.glob("#{dir}/**.rb").sort end |
#require_classes ⇒ Object
28 29 30 31 32 33 |
# File 'lib/quality/directory_of_classes.rb', line 28 def require_classes basenames.each do |basename| path = "#{dir}/#{basename}" require_relative path end end |
#symbols_and_classes ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/quality/directory_of_classes.rb', line 35 def symbols_and_classes @symbols_and_classes ||= filenames.map do |filename| basename = File.basename(filename, '.rb') class_name = "#{module_name}::#{basename.camelize}#{@class_suffix}" clazz = class_name.constantize symbol = basename.to_sym [symbol, clazz] end end |