Class: Jekyll::Archimate::ConditionalFile
- Inherits:
-
Object
- Object
- Jekyll::Archimate::ConditionalFile
- Defined in:
- lib/jekyll/archimate/conditional_file.rb
Overview
Persists an ArchiMate diagram to a file
Instance Attribute Summary collapse
-
#archimate_file ⇒ Object
readonly
Returns the value of attribute archimate_file.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(site, dir, name, archimate_file) ⇒ ConditionalFile
constructor
A new instance of ConditionalFile.
- #needs_write?(content) ⇒ Boolean
-
#write(content) ⇒ Object
Writes content to filename if * File doesn’t exit * Or File content is different than content.
Constructor Details
#initialize(site, dir, name, archimate_file) ⇒ ConditionalFile
Returns a new instance of ConditionalFile.
14 15 16 17 18 19 20 21 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 14 def initialize(site, dir, name, archimate_file) @site = site @dir = dir @name = name @archimate_file = archimate_file @filename = File.join(site.source, dir, name) @relative_path = File.join(dir, name) end |
Instance Attribute Details
#archimate_file ⇒ Object (readonly)
Returns the value of attribute archimate_file.
11 12 13 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 11 def archimate_file @archimate_file end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
8 9 10 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 8 def dir @dir end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
10 11 12 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 10 def filename @filename end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 9 def name @name end |
#relative_path ⇒ Object (readonly)
Returns the value of attribute relative_path.
12 13 14 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 12 def relative_path @relative_path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
7 8 9 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 7 def site @site end |
Instance Method Details
#needs_write?(content) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 23 def needs_write?(content) return true unless File.exist?(filename) return true if archimate_file.modified_time.to_i > File.mtime(filename).to_i File.read(filename) != content end |
#write(content) ⇒ Object
Writes content to filename if
-
File doesn’t exit
-
Or File content is different than content
32 33 34 35 |
# File 'lib/jekyll/archimate/conditional_file.rb', line 32 def write(content) return unless needs_write?(content) Jekyll.logger.info "Rendering #{relative_path}" end |