Class: Awestruct::Dependencies
- Inherits:
-
Object
- Object
- Awestruct::Dependencies
- Defined in:
- lib/awestruct/dependencies.rb
Instance Attribute Summary collapse
-
#content_hash ⇒ Object
Returns the value of attribute content_hash.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#dependents ⇒ Object
readonly
Returns the value of attribute dependents.
-
#has_changed_content ⇒ Object
readonly
Returns the value of attribute has_changed_content.
-
#has_changed_keys ⇒ Object
readonly
Returns the value of attribute has_changed_keys.
-
#key_dependencies ⇒ Object
readonly
Returns the value of attribute key_dependencies.
-
#key_dependents ⇒ Object
readonly
Returns the value of attribute key_dependents.
-
#key_hash ⇒ Object
Returns the value of attribute key_hash.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Class Method Summary collapse
- .pop_page ⇒ Object
- .push_page(page) ⇒ Object
- .should_track_dependencies ⇒ Object
- .top_page ⇒ Object
- .track_dependencies=(bol) ⇒ Object
- .track_dependency(dep) ⇒ Object
- .track_key_dependency(dep, key) ⇒ Object
Instance Method Summary collapse
- #<<(dep) ⇒ Object
- #add_dependency(dep) ⇒ Object
- #add_dependent(dep) ⇒ Object
- #add_key_dependency(dep) ⇒ Object
- #add_key_dependent(dep) ⇒ Object
- #clear ⇒ Object
- #find_page_by_path(path) ⇒ Object
-
#initialize(page) ⇒ Dependencies
constructor
A new instance of Dependencies.
- #load! ⇒ Object
- #persist! ⇒ Object
- #remove_dependent(dep) ⇒ Object
Constructor Details
#initialize(page) ⇒ Dependencies
Returns a new instance of Dependencies.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/awestruct/dependencies.rb', line 63 def initialize(page) @page = page @dependencies = Set.new @key_dependencies = Set.new @dependents = Set.new @key_dependents = Set.new @content_hash = nil @key_hash = nil @has_changed_content = false @has_changed_keys = false end |
Instance Attribute Details
#content_hash ⇒ Object
Returns the value of attribute content_hash.
9 10 11 |
# File 'lib/awestruct/dependencies.rb', line 9 def content_hash @content_hash end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
5 6 7 |
# File 'lib/awestruct/dependencies.rb', line 5 def dependencies @dependencies end |
#dependents ⇒ Object (readonly)
Returns the value of attribute dependents.
7 8 9 |
# File 'lib/awestruct/dependencies.rb', line 7 def dependents @dependents end |
#has_changed_content ⇒ Object (readonly)
Returns the value of attribute has_changed_content.
11 12 13 |
# File 'lib/awestruct/dependencies.rb', line 11 def has_changed_content @has_changed_content end |
#has_changed_keys ⇒ Object (readonly)
Returns the value of attribute has_changed_keys.
12 13 14 |
# File 'lib/awestruct/dependencies.rb', line 12 def has_changed_keys @has_changed_keys end |
#key_dependencies ⇒ Object (readonly)
Returns the value of attribute key_dependencies.
6 7 8 |
# File 'lib/awestruct/dependencies.rb', line 6 def key_dependencies @key_dependencies end |
#key_dependents ⇒ Object (readonly)
Returns the value of attribute key_dependents.
8 9 10 |
# File 'lib/awestruct/dependencies.rb', line 8 def key_dependents @key_dependents end |
#key_hash ⇒ Object
Returns the value of attribute key_hash.
10 11 12 |
# File 'lib/awestruct/dependencies.rb', line 10 def key_hash @key_hash end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'lib/awestruct/dependencies.rb', line 4 def page @page end |
Class Method Details
.pop_page ⇒ Object
40 41 42 43 |
# File 'lib/awestruct/dependencies.rb', line 40 def self.pop_page page = @pages.pop $LOG.debug "pop #{page.output_path} #{@pages.empty?}" if $LOG.debug? end |
.push_page(page) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/awestruct/dependencies.rb', line 28 def self.push_page(page) $LOG.debug "push #{page.output_path}" if $LOG.debug? if ( top_page.nil? ) $LOG.debug "clearing dependencies" if $LOG.debug? page.dependencies.clear else $LOG.debug "adding page as a dependency to top_page" if $LOG.debug? top_page.dependencies.add_dependency( page ) end @pages.push( page ) end |
.should_track_dependencies ⇒ Object
19 20 21 |
# File 'lib/awestruct/dependencies.rb', line 19 def self.should_track_dependencies @track_dependencies end |
.top_page ⇒ Object
23 24 25 26 |
# File 'lib/awestruct/dependencies.rb', line 23 def self.top_page @pages ||= [] @pages.first end |
.track_dependencies=(bol) ⇒ Object
15 16 17 |
# File 'lib/awestruct/dependencies.rb', line 15 def self.track_dependencies=(bol) @track_dependencies = bol end |
.track_dependency(dep) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/awestruct/dependencies.rb', line 46 def self.track_dependency(dep) return if top_page.nil? return if top_page == dep $LOG.debug "dep #{top_page.relative_source_path} - #{dep.relative_source_path}" if $LOG.debug? top_page.dependencies.add_dependency(dep) end |
.track_key_dependency(dep, key) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/awestruct/dependencies.rb', line 53 def self.track_key_dependency(dep, key) return if !Awestruct::Dependencies.should_track_dependencies return if top_page.nil? return if top_page == dep $LOG.debug "dep key #{top_page.relative_source_path} - #{dep.relative_source_path} -> #{key}" if $LOG.debug? $LOG.debug "callers #{Kernel.caller}" if $LOG.debug? top_page.dependencies.add_key_dependency(dep) end |
Instance Method Details
#<<(dep) ⇒ Object
103 104 105 |
# File 'lib/awestruct/dependencies.rb', line 103 def <<(dep) add_dependency( dep ) end |
#add_dependency(dep) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/awestruct/dependencies.rb', line 107 def add_dependency(dep) return if dep.nil? return if @page.do_not_track_dependencies return if @page.output_path.nil? return if dep == @page $LOG.debug "adding dependency #{dep.source_path} to #{page.source_path}" if $LOG.debug? @dependencies << dep dep.dependencies.add_dependent( page ) end |
#add_dependent(dep) ⇒ Object
126 127 128 129 |
# File 'lib/awestruct/dependencies.rb', line 126 def add_dependent(dep) return if dep.nil? @dependents << dep end |
#add_key_dependency(dep) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/awestruct/dependencies.rb', line 117 def add_key_dependency(dep) return if dep.nil? return if @page.do_not_track_dependencies return if @page.output_path.nil? return if dep == @page @key_dependencies << dep dep.dependencies.add_key_dependent( page ) end |
#add_key_dependent(dep) ⇒ Object
131 132 133 134 |
# File 'lib/awestruct/dependencies.rb', line 131 def add_key_dependent(dep) return if dep.nil? @key_dependents << dep end |
#clear ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/awestruct/dependencies.rb', line 141 def clear @dependencies.clear @dependents.each do |d| if (d.instance_of? Awestruct::Dependencies) d.remove_dependent( page ) else d.dependencies.remove_dependent( page ) end end end |
#find_page_by_path(path) ⇒ Object
196 197 198 |
# File 'lib/awestruct/dependencies.rb', line 196 def find_page_by_path(path) page.site.pages_by_relative_source_path[ path ] end |
#load! ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/awestruct/dependencies.rb', line 169 def load! return if page.output_path.nil? || page.output_path == '' file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path ) $LOG.debug "load #{file}" if $LOG.debug? if ( File.exist?( file ) ) File.open( file, 'r' ) do |file| file.each_line do |line| type, path = line.split(':') path ||= "" path.strip! if type.eql? 'c' or type.eql? 'k' d = find_page_by_path( path ) unless d.nil? add_dependency( d ) if 'c'.eql? type add_key_dependency( d ) if 'k'.eql? type end else self.content_hash = path if 'ch'.eql? type self.key_hash = path if 'kh'.eql? type end end end return true end false end |
#persist! ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/awestruct/dependencies.rb', line 152 def persist! return if page.output_path.nil? || page.output_path == '' file = File.join( @page.site.config.dir.to_s, '.awestruct', 'dependency-cache', page.output_path ) $LOG.debug "store #{file}" if $LOG.debug? FileUtils.mkdir_p( File.dirname( file ) ) File.open( file, 'w' ) do |file| file.puts "ch:#{@content_hash}" file.puts "kh:#{@key_hash}" @dependencies.collect{|e| e.relative_source_path }.uniq.each do |d| file.puts "c:#{d}" unless d.nil? end @key_dependencies.collect{|e| e.relative_source_path }.uniq.each do |d| file.puts "k:#{d}" unless d.nil? end end end |
#remove_dependent(dep) ⇒ Object
136 137 138 139 |
# File 'lib/awestruct/dependencies.rb', line 136 def remove_dependent(dep) return if dep.nil? @dependents.delete( dep ) end |