Class: DTK::DSL::FileObj

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/file_obj.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_type, file_path, opts = {}) ⇒ FileObj

opts can have keys

:dir_path
:current_dir
:content 
:file_parser - this is class


25
26
27
28
29
30
31
32
33
34
35
# 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

Instance Attribute Details

#file_typeObject (readonly)

Returns the value of attribute file_type.



38
39
40
# File 'lib/dsl/file_obj.rb', line 38

def file_type
  @file_type
end

#yaml_parse_hashObject

Returns the value of attribute yaml_parse_hash.



37
38
39
# File 'lib/dsl/file_obj.rb', line 37

def yaml_parse_hash
  @yaml_parse_hash
end

Instance Method Details

#add_parse_content!(parse_template_type, opts = {}) ⇒ Object

opts can have keys:

:dsl_version


42
43
44
45
# File 'lib/dsl/file_obj.rb', line 42

def add_parse_content!(parse_template_type, opts = {})
  parse_content(parse_template_type, opts)
  self
end

#contentObject



53
54
55
# File 'lib/dsl/file_obj.rb', line 53

def content
  @content || raise(Error, 'Method should not be called if @content is nil')
end

#content?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/dsl/file_obj.rb', line 56

def content?
  @content 
end

#content_or_raise_errorObject



50
51
52
# File 'lib/dsl/file_obj.rb', line 50

def content_or_raise_error
  @content || raise(Error::Usage, error_msg_no_content)
end

#exists?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/dsl/file_obj.rb', line 70

def exists?
  ! @content.nil?
end

#hash_content?Boolean

Returns:

  • (Boolean)


78
79
80
# 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 = {}) ⇒ Object



46
47
48
# 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?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/dsl/file_obj.rb', line 74

def path?
  @path
end

#raise_error_if_no_contentObject

Raises:



60
61
62
63
# 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) ⇒ Object

Raises:



65
66
67
68
# 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