Class: DTK::DSL::FileObj
- Inherits:
-
Object
- Object
- DTK::DSL::FileObj
- Defined in:
- lib/dsl/file_obj.rb
Instance Attribute Summary collapse
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#yaml_parse_hash ⇒ Object
Returns the value of attribute yaml_parse_hash.
Instance Method Summary collapse
-
#add_parse_content!(parse_template_type, opts = {}) ⇒ Object
opts can have keys: :dsl_version.
- #content ⇒ Object
- #content? ⇒ Boolean
- #content_or_raise_error ⇒ Object
- #exists? ⇒ Boolean
- #hash_content? ⇒ Boolean
-
#initialize(file_type, file_path, opts = {}) ⇒ FileObj
constructor
opts can have keys :dir_path :current_dir :content :file_parser - this is class.
- #parse_content(parse_template_type, opts = {}) ⇒ Object
- #path? ⇒ Boolean
- #raise_error_if_no_content ⇒ Object
- #raise_error_if_no_content_flag(type) ⇒ Object
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_type ⇒ Object (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_hash ⇒ Object
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 |
#content ⇒ Object
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
56 57 58 |
# File 'lib/dsl/file_obj.rb', line 56 def content? @content end |
#content_or_raise_error ⇒ Object
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
70 71 72 |
# File 'lib/dsl/file_obj.rb', line 70 def exists? ! @content.nil? end |
#hash_content? ⇒ 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
74 75 76 |
# File 'lib/dsl/file_obj.rb', line 74 def path? @path end |