Class: Pangea::Entities::Template
- Defined in:
- lib/pangea/entities/template.rb
Instance Method Summary collapse
- #cache_key ⇒ Object
- #content_without_metadata ⇒ Object
- #from_file? ⇒ Boolean
- #metadata ⇒ Object
- #source ⇒ Object
- #validate! ⇒ Object
Instance Method Details
#cache_key ⇒ Object
41 42 43 44 |
# File 'lib/pangea/entities/template.rb', line 41 def cache_key parts = [namespace, project, name].compact parts.join('/') end |
#content_without_metadata ⇒ Object
78 79 80 81 82 83 |
# File 'lib/pangea/entities/template.rb', line 78 def return content unless content.start_with?("# @") lines = content.lines lines.drop_while { |line| line.start_with?("# @") }.join end |
#from_file? ⇒ Boolean
37 38 39 |
# File 'lib/pangea/entities/template.rb', line 37 def from_file? !file_path.nil? end |
#metadata ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pangea/entities/template.rb', line 61 def return {} unless content.start_with?("# @") = {} content.lines.each do |line| break unless line.start_with?("# @") if line =~ /# @(\w+):\s*(.+)$/ key = $1.to_sym value = $2.strip [key] = value end end end |
#source ⇒ Object
33 34 35 |
# File 'lib/pangea/entities/template.rb', line 33 def source file_path || "<inline:#{name}>" end |
#validate! ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pangea/entities/template.rb', line 46 def validate! errors = [] if content.strip.empty? errors << "Template content cannot be empty" end if content.include?("<%") || content.include?("{{") errors << "Template appears to contain ERB or Mustache syntax (not supported)" end raise ValidationError, errors.join(", ") unless errors.empty? true end |