class DTK::DSL::FileObj

Attributes

file_type[R]
yaml_parse_hash[RW]

Public Class Methods

new(file_type, file_path, opts = {}) click to toggle source

opts can have keys

:dir_path
:current_dir
:content 
:file_parser - this is class
# File lib/dsl/file_obj.rb, line 25
def initialize(file_type, file_path, opts = {})
  @file_type         = file_type
  @path              = file_path
  @dir_path          = opts[:dir_path]
  @current_dir       = opts[:current_dir]  
  @content           = opts[:content]
  @file_parser_class = opts[:file_parser] || FileParser
  # below computed on demand
  @parsed_templates = {}
  @yaml_parse_hash = nil
end

Public Instance Methods

add_parse_content!(parse_template_type, opts = {}) click to toggle source

opts can have keys:

:dsl_version
# File lib/dsl/file_obj.rb, line 42
def add_parse_content!(parse_template_type, opts = {})
  parse_content(parse_template_type, opts)
  self
end
content() click to toggle source
# File lib/dsl/file_obj.rb, line 53
def content
  @content || raise(Error, 'Method should not be called if @content is nil')
end
content?() click to toggle source
# File lib/dsl/file_obj.rb, line 56
def content?
  @content 
end
content_or_raise_error() click to toggle source
# File lib/dsl/file_obj.rb, line 50
def content_or_raise_error
  @content || raise(Error::Usage, error_msg_no_content)
end
exists?() click to toggle source
# File lib/dsl/file_obj.rb, line 70
def exists?
  ! @content.nil?
end
hash_content?() click to toggle source
# File lib/dsl/file_obj.rb, line 78
def hash_content?
  @file_parser_class.yaml_parse!(self) if exists?
end
parse_content(parse_template_type, opts = {}) click to toggle source
# File lib/dsl/file_obj.rb, line 46
def parse_content(parse_template_type, opts = {})
  @parsed_templates[parse_template_type] ||= @file_parser_class.parse_content(parse_template_type, self, opts)
end
path?() click to toggle source
# File lib/dsl/file_obj.rb, line 74
def path?
  @path
end
raise_error_if_no_content() click to toggle source
# File lib/dsl/file_obj.rb, line 60
def raise_error_if_no_content
  raise(Error::Usage, error_msg_no_content) unless @content
  self
end
raise_error_if_no_content_flag(type) click to toggle source
# File lib/dsl/file_obj.rb, line 65
def raise_error_if_no_content_flag(type)
  raise(Error::Usage, error_msg_no_content_flag(type)) unless @content
  self
end

Private Instance Methods

dir_ref() click to toggle source
# File lib/dsl/file_obj.rb, line 106
def dir_ref
  if @dir_path 
    "specified directory '#{@dir_path}'" 
  elsif @current_dir
    "current directory '#{@current_dir}'"
  else
    'directory'
  end
end
error_msg_no_content() click to toggle source
# File lib/dsl/file_obj.rb, line 84
def error_msg_no_content
  if @path
    "No #{file_ref} found at '#{@path}'"
  else
    "Cannot find a #{file_ref} in the #{dir_ref} or ones nested under it"
  end
end
error_msg_no_content_flag(type) click to toggle source
# File lib/dsl/file_obj.rb, line 92
def error_msg_no_content_flag(type)
  type = type.to_s
  type = type.slice!(0..(type.index('_')-1))
  if @path
    "No #{file_ref} found at '#{@path}'"
  else
    "Cannot find a #{type} #{file_ref} in the #{dir_ref}"
  end
end
file_ref() click to toggle source
# File lib/dsl/file_obj.rb, line 102
def file_ref
  (@file_type && @file_type.print_name) || 'DSL file'
end