class Rmk::VFile

virtual file which represent a real OS file

Attributes

is_src[RW]
output_ref_build[RW]

build which include this file as output file @return [Rmk::Build]

path[R]
state[RW]

get or set out file state return [:eixst, :create, true, nil]

vpath[R]

Public Class Methods

generate_modified_id(path) click to toggle source
# File lib/rmk/vfile.rb, line 8
def self.generate_modified_id(path) File.mtime(path).to_i end
new(rmk:, path:, vpath:nil, is_src:false) click to toggle source

create VFile @param rmk [Rmk] @param path [String] file's absolute path, must be normalized @param vpath [String] file's virtual path

# File lib/rmk/vfile.rb, line 26
def initialize(rmk:, path:, vpath:nil, is_src:false)
        @rmk, @path, @vpath, @is_src = rmk, path, vpath || nil, is_src
        @input_ref_builds, @order_ref_builds = [], []
        @output_ref_build = nil unless is_src
end

Public Instance Methods

change_to_out!(outfile) click to toggle source

change to out file @param outfile [Rmk::VFile] target file @return [self]

# File lib/rmk/vfile.rb, line 51
def change_to_out!(outfile)
        raise "outfile '#{@path}' can't change to outfile" if src?
        raise "outfile '#{@path}' can't change to srcfile" if outfile.src?
        unless @path == outfile.path && @vpath == outfile.vpath
                raise "srcfile '#{@path}' can't change to outfile '#{outfile.path}'"
        end
        @is_src = false
        @input_ref_builds.concat outfile.input_ref_builds
        @order_ref_builds.concat outfile.order_ref_builds
        @output_ref_build = outfile.output_ref_build
        self
end
check_for_build() click to toggle source

check build's to run as srcfile, means file must be exist and can't check more than one time

# File lib/rmk/vfile.rb, line 70
def check_for_build
        lmid, cmid = load_modified_id, generate_modified_id
        return updated! false if lmid == cmid
        store_modified_id cmid
        updated! true
end
check_for_parse() click to toggle source

check outdated or not as srcfile at parse phaze(not build phaze)

# File lib/rmk/vfile.rb, line 78
def check_for_parse
        load_modified_id != generate_modified_id
end
generate_modified_id() click to toggle source

generate file's modified id from current disk content

# File lib/rmk/vfile.rb, line 37
def generate_modified_id; Rmk::VFile.generate_modified_id @path end
input_ref_builds() click to toggle source

builds which include this file as input file

# File lib/rmk/vfile.rb, line 13
def input_ref_builds; @input_ref_builds end
load_modified_id() click to toggle source

load last time modified id from system database @return [Object] last stored modified id or nil for no last stored id

# File lib/rmk/vfile.rb, line 41
def load_modified_id; @rmk.mid_storage[@path] end
order_ref_builds() click to toggle source

builds which include this file as order-only file

# File lib/rmk/vfile.rb, line 16
def order_ref_builds; @order_ref_builds end
src?() click to toggle source
# File lib/rmk/vfile.rb, line 10
def src?; @is_src end
store_modified_id(mid) click to toggle source

store modified id to system database for next time check @param mid [Object] modified id @return [Object] stored modified id

# File lib/rmk/vfile.rb, line 46
def store_modified_id(mid) @rmk.mid_storage[@path] = mid end
updated!(modified) click to toggle source
# File lib/rmk/vfile.rb, line 64
def updated!(modified)
        input_ref_builds.each{|build| build.input_updated! modified}
        order_ref_builds.each{|build| build.order_updated! modified}
end