Class: CLI::Mastermind::Loader
- Inherits:
-
Object
- Object
- CLI::Mastermind::Loader
- Defined in:
- lib/cli/mastermind/loader.rb,
lib/cli/mastermind/loader/planfile_loader.rb
Direct Known Subclasses
Defined Under Namespace
Classes: PlanfileLoader
Constant Summary collapse
- @@loaders =
[]
Class Attribute Summary collapse
-
.loadable_extensions ⇒ Object
readonly
Returns the value of attribute loadable_extensions.
Class Method Summary collapse
- .can_load?(extension) ⇒ Boolean
- .find_loader(extension) ⇒ Object
- .inherited(subclass) ⇒ Object
- .load(filename) ⇒ Object
-
.load_all(files) ⇒ Object
Loads a particular plan from the filesystem.
- .supported_extensions ⇒ Object
Class Attribute Details
.loadable_extensions ⇒ Object (readonly)
Returns the value of attribute loadable_extensions.
4 5 6 |
# File 'lib/cli/mastermind/loader.rb', line 4 def loadable_extensions @loadable_extensions end |
Class Method Details
.can_load?(extension) ⇒ Boolean
23 24 25 |
# File 'lib/cli/mastermind/loader.rb', line 23 def can_load?(extension) @loadable_extensions.include? extension end |
.find_loader(extension) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cli/mastermind/loader.rb', line 11 def find_loader(extension) loader = @@loaders.find { |l| l.can_load? extension } raise UnsupportedFileTypeError.new(extension) unless loader loader end |
.inherited(subclass) ⇒ Object
7 8 9 |
# File 'lib/cli/mastermind/loader.rb', line 7 def inherited(subclass) @@loaders << subclass end |
.load(filename) ⇒ Object
27 28 29 |
# File 'lib/cli/mastermind/loader.rb', line 27 def load(filename) raise NotImplementedError end |
.load_all(files) ⇒ Object
Loads a particular plan from the filesystem.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cli/mastermind/loader.rb', line 32 def load_all(files) temp_plan = ParentPlan.new('INTERNAL PLAN HOLDER') plans = files.map do |file| ext = File.extname(file) loader = Loader.find_loader(ext) temp_plan.add_children loader.load(file) end temp_plan end |
.supported_extensions ⇒ Object
19 20 21 |
# File 'lib/cli/mastermind/loader.rb', line 19 def supported_extensions @@loaders.flat_map { |l| l.loadable_extensions } end |