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.
19 20 21 22 23 |
# File 'lib/quality/directory_of_classes.rb', line 19 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.
17 18 19 |
# File 'lib/quality/directory_of_classes.rb', line 17 def dir @dir end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
17 18 19 |
# File 'lib/quality/directory_of_classes.rb', line 17 def module_name @module_name end |
Instance Method Details
#basenames ⇒ Object
29 30 31 |
# File 'lib/quality/directory_of_classes.rb', line 29 def basenames filenames.map { |filename| File.basename(filename) } end |
#basenames_without_extension ⇒ Object
33 34 35 |
# File 'lib/quality/directory_of_classes.rb', line 33 def basenames_without_extension filenames.map { |filename| File.basename(filename, '.*') } end |
#filenames ⇒ Object
25 26 27 |
# File 'lib/quality/directory_of_classes.rb', line 25 def filenames Dir.glob("#{dir}/**.rb").sort end |
#require_classes ⇒ Object
37 38 39 40 41 42 |
# File 'lib/quality/directory_of_classes.rb', line 37 def require_classes basenames.each do |basename| path = "#{dir}/#{basename}" require_relative path end end |
#symbols_and_classes ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/quality/directory_of_classes.rb', line 44 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 |