Class: DTK::DSL::FileType

Inherits:
Object
  • Object
show all
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

CommonModule, ModuleRefsLock, ServiceInstance

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

Instance Method Summary collapse

Class Method Details

.backup_pathObject



79
80
81
# File 'lib/dsl/file_type.rb', line 79

def self.backup_path
  backup_path_from_canonical_path(canonical_path)
end

.base_dirObject



86
87
88
# File 'lib/dsl/file_type.rb', line 86

def self.base_dir
  nil
end

.canonical_pathObject



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

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

.regexpObject



67
68
69
# File 'lib/dsl/file_type.rb', line 67

def self.regexp
  matching_type_def(:regexp)
end

.type_level_typeObject



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_pathObject



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_dirObject

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_pathObject

This can be over-written



75
76
77
# File 'lib/dsl/file_type.rb', line 75

def canonical_path
  self.class.canonical_path
end

#indexObject

This can be over-written



110
111
112
# File 'lib/dsl/file_type.rb', line 110

def index
  self.class.to_s
end

#matches?(file_path, opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dsl/file_type.rb', line 30

def matches?(file_path, opts = {})
  Match.matches?(self, file_path, opts)
end