class DTK::DSL::FileType

Constants

BASE_CLASS
FILE_PREFIX
TYPES

Public Class Methods

backup_path() click to toggle source
# File lib/dsl/file_type.rb, line 84
def self.backup_path
  backup_path_from_canonical_path(canonical_path)
end
base_dir() click to toggle source
# File lib/dsl/file_type.rb, line 91
def self.base_dir
  nil
end
canonical_path() click to toggle source
# File lib/dsl/file_type.rb, line 76
def self.canonical_path
  canonical_path_lambda.call({})
end
file_type_instance_if_match?(file_path) click to toggle source

If match it retuns a hash with params that can be used to create a File Type instance

# File lib/dsl/file_type.rb, line 101
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 = {}) click to toggle source

opts can have keys:

:exact - Booelan (default: false) - meaning regexp completely matches file_path
# 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) click to toggle source

Returns array of MatchingFiles or nil

# 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() click to toggle source

regexps, except for one in :instance_match_lambda, purposely do not have ^ or $ so calling function can insert these depending on context

regexp() click to toggle source
# File lib/dsl/file_type.rb, line 72
def self.regexp
  matching_type_def(:regexp)
end
type_level_type() click to toggle source
# File lib/dsl/file_type.rb, line 110
def self.type_level_type
  raise Error::NoMethodForConcreteClass.new(self)
end

Private Class Methods

backup_path_from_canonical_path(canonical_path) click to toggle source
# File lib/dsl/file_type.rb, line 142
def self.backup_path_from_canonical_path(canonical_path)
  split_path = canonical_path.split('/')
  file_path = split_path.pop
  backup_file_path = "#{FILE_PREFIX}.#{file_path}"
  split_path.empty? ? backup_file_path : "#{split_path.join('/')}/#{backup_file_path}"      
end
canonical_path_lambda() click to toggle source
# File lib/dsl/file_type.rb, line 137
def self.canonical_path_lambda
  matching_type_def(:canonical_path_lambda)
end
matching_type_def(key, klass = nil, orig_klass = nil) click to toggle source

The method matching_type_def starts at tpe and looks to see if or recursive parents have definition

# File lib/dsl/file_type.rb, line 123
def self.matching_type_def(key, klass = nil, orig_klass = nil)
  klass      ||= self
  orig_klass ||= self
  fail Error, "Type '#{orig_klass}' is not in TYPES" if klass == BASE_CLASS 
  if type_def_hash = TYPES[klass] 
    type_def_hash[key]
  else
    matching_type_def(key, klass.superclass, orig_klass)
  end
end

Public Instance Methods

backup_path() click to toggle source
# File lib/dsl/file_type.rb, line 87
def backup_path
  self.class.backup_path_from_canonical_path(canonical_path)
end
base_dir() click to toggle source

This can be over-written

# File lib/dsl/file_type.rb, line 95
def base_dir
  self.class.base_dir
end
canonical_path() click to toggle source

This can be over-written

# File lib/dsl/file_type.rb, line 80
def canonical_path
  self.class.canonical_path
end
index() click to toggle source

This can be over-written

# File lib/dsl/file_type.rb, line 115
def index
  self.class.to_s
end
matches?(file_path, opts = {}) click to toggle source
# File lib/dsl/file_type.rb, line 30
def matches?(file_path, opts = {})
  Match.matches?(self, file_path, opts)
end

Private Instance Methods

matching_type_def(key) click to toggle source
# File lib/dsl/file_type.rb, line 133
def matching_type_def(key)
  self.class.matching_type_def(key)
end