Class: Jekyll::Archimate::ConditionalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/archimate/conditional_file.rb

Overview

Persists an ArchiMate diagram to a file

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (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

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/jekyll/archimate/conditional_file.rb', line 8

def dir
  @dir
end

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/jekyll/archimate/conditional_file.rb', line 10

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/jekyll/archimate/conditional_file.rb', line 9

def name
  @name
end

#relative_pathObject (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

#siteObject (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

Returns:

  • (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