Class: AutoC::Module::State
- Inherits:
-
Hash
- Object
- Hash
- AutoC::Module::State
- Defined in:
- lib/autoc/module.rb
Instance Attribute Summary collapse
-
#module ⇒ Object
readonly
Returns the value of attribute module.
Instance Method Summary collapse
- #collect ⇒ Object
- #file_name ⇒ Object
-
#initialize(m) ⇒ State
constructor
A new instance of State.
- #read ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(m) ⇒ State
Returns a new instance of State.
110 111 112 113 |
# File 'lib/autoc/module.rb', line 110 def initialize(m) super @module = m end |
Instance Attribute Details
#module ⇒ Object (readonly)
Returns the value of attribute module.
106 107 108 |
# File 'lib/autoc/module.rb', line 106 def module @module end |
Instance Method Details
#collect ⇒ Object
115 116 117 118 119 |
# File 'lib/autoc/module.rb', line 115 def collect self[self.module.header.file_name] = self.module.header.digest self.module.sources.each { |source| self[source.file_name] = source.digest } self end |
#file_name ⇒ Object
108 |
# File 'lib/autoc/module.rb', line 108 def file_name = "#{self.module.name}.state" |
#read ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/autoc/module.rb', line 121 def read if self.module.stateful? && File.exist?(file_name) # It's OK not to have this file but if it exists it must have proper contents io = File.open(file_name, 'rt', chomp: true) begin hash = {} io.readlines.each do |x| raise 'improper state file format' if (/\s*([^\s]+)\s+\*(.*)/ =~ x).nil? hash[$2] = $1 end update(hash) ensure io.close end end self end |
#write ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/autoc/module.rb', line 139 def write io = File.open(file_name, 'wt') begin begin each { |file_name, digest| io << "#{digest} *#{file_name}\n" } ensure io.close end rescue File.unlink(file_name) # Delete improperly rendered state file raise end self end |