Class: DTK::DSL::FileType
- Inherits:
-
Object
- Object
- DTK::DSL::FileType
- Defined in:
- lib/dsl/file_type.rb,
lib/dsl/file_type/match.rb,
lib/dsl/file_type/subclasses.rb,
lib/dsl/file_type/matching_files.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CommonModule, Match, MatchingFiles, ModuleRefsLock, ServiceInstance
Constant Summary collapse
- TYPES =
{ CommonModule::DSLFile::Top => { :regexp => Regexp.new("dtk\.module\.(yml|yaml)"), :canonical_path_lambda => lambda { |_params| 'dtk.module.yaml' }, :print_name => 'module DSL file' }, ModuleRefsLock::DSLFile::Top => { :regexp => Regexp.new("dtk\.module\.lock"), :canonical_path_lambda => lambda { |_params| 'dtk\.modules.lock' }, :print_name => 'module refs lock DSL file' }, ServiceInstance::DSLFile::Top => { :regexp => Regexp.new("dtk\.service\.(yml|yaml)"), :canonical_path_lambda => lambda { |_params| 'dtk.service.yaml' }, :print_name => 'service DSL file' }, ServiceInstance::NestedModule::DSLFile::Top => { :regexp => Regexp.new("dtk\.module\.(yml|yaml)"), :canonical_path_lambda => lambda { |_params| 'dtk.module.yaml' }, :print_name => 'nested module DSL file' } }
Class Method Summary collapse
- .backup_path ⇒ Object
- .base_dir ⇒ Object
- .canonical_path ⇒ Object
-
.file_type_instance_if_match?(file_path) ⇒ Boolean
If match it retuns a hash with params that can be used to create a File Type instance.
-
.matches?(file_path, opts = {}) ⇒ Boolean
opts can have keys: :exact - Booelan (default: false) - meaning regexp completely matches file_path.
-
.matching_files_array?(file_type_classes, file_paths) ⇒ Boolean
Returns array of MatchingFiles or nil.
-
.print_name ⇒ Object
regexps, except for one in :instance_match_lambda, purposely do not have ^ or $ so calling function can insert these depending on context.
- .regexp ⇒ Object
- .type_level_type ⇒ Object
Instance Method Summary collapse
- #backup_path ⇒ Object
-
#base_dir ⇒ Object
This can be over-written.
-
#canonical_path ⇒ Object
This can be over-written.
-
#index ⇒ Object
This can be over-written.
- #matches?(file_path, opts = {}) ⇒ Boolean
Class Method Details
.backup_path ⇒ Object
79 80 81 |
# File 'lib/dsl/file_type.rb', line 79 def self.backup_path backup_path_from_canonical_path(canonical_path) end |
.base_dir ⇒ Object
86 87 88 |
# File 'lib/dsl/file_type.rb', line 86 def self.base_dir nil end |
.canonical_path ⇒ Object
71 72 73 |
# File 'lib/dsl/file_type.rb', line 71 def self.canonical_path canonical_path_lambda.call({}) end |
.file_type_instance_if_match?(file_path) ⇒ Boolean
If match it retuns a hash with params that can be used to create a File Type instance
96 97 98 99 100 101 102 103 |
# File 'lib/dsl/file_type.rb', line 96 def self.file_type_instance_if_match?(file_path) # just want to match 'this' and dont want to match parent so not using matching_type_def if instance_match_lambda = TYPES[self][:instance_match_lambda] if hash_params_for_new = instance_match_lambda.call(file_path) new(hash_params_for_new) end end end |
.matches?(file_path, opts = {}) ⇒ Boolean
opts can have keys:
:exact - Booelan (default: false) - meaning regexp completely matches file_path
27 28 29 |
# File 'lib/dsl/file_type.rb', line 27 def self.matches?(file_path, opts = {}) Match.matches?(self, file_path, opts) end |
.matching_files_array?(file_type_classes, file_paths) ⇒ Boolean
Returns array of MatchingFiles or nil
35 36 37 |
# File 'lib/dsl/file_type.rb', line 35 def self.matching_files_array?(file_type_classes, file_paths) MatchingFiles.matching_files_array?(file_type_classes, file_paths) end |
.print_name ⇒ Object
regexps, except for one in :instance_match_lambda, purposely do not have ^ or $ so calling function can insert these depending on context
63 64 65 |
# File 'lib/dsl/file_type.rb', line 63 def self.print_name matching_type_def(:print_name) end |
.regexp ⇒ Object
67 68 69 |
# File 'lib/dsl/file_type.rb', line 67 def self.regexp matching_type_def(:regexp) end |
.type_level_type ⇒ Object
105 106 107 |
# File 'lib/dsl/file_type.rb', line 105 def self.type_level_type raise Error::NoMethodForConcreteClass.new(self) end |
Instance Method Details
#backup_path ⇒ Object
82 83 84 |
# File 'lib/dsl/file_type.rb', line 82 def backup_path self.class.backup_path_from_canonical_path(canonical_path) end |
#base_dir ⇒ Object
This can be over-written
90 91 92 |
# File 'lib/dsl/file_type.rb', line 90 def base_dir self.class.base_dir end |
#canonical_path ⇒ Object
This can be over-written
75 76 77 |
# File 'lib/dsl/file_type.rb', line 75 def canonical_path self.class.canonical_path end |
#index ⇒ Object
This can be over-written
110 111 112 |
# File 'lib/dsl/file_type.rb', line 110 def index self.class.to_s end |