Class: Rmk::VFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rmk/vfile.rb,
lib/rmk/rmk.rb

Overview

virtual file which represent a real OS file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rmk:, path:, vpath: nil, is_src: false) ⇒ VFile

create VFile

Parameters:

  • rmk (Rmk)
  • path (String)

    file’s absolute path, must be normalized

  • vpath (String) (defaults to: nil)

    file’s virtual path



26
27
28
29
30
# 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

Instance Attribute Details

#is_srcObject

Returns the value of attribute is_src.



6
7
8
# File 'lib/rmk/vfile.rb', line 6

def is_src
  @is_src
end

#output_ref_buildRmk::Build

build which include this file as output file

Returns:



20
21
22
# File 'lib/rmk/vfile.rb', line 20

def output_ref_build
  @output_ref_build
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/rmk/vfile.rb', line 5

def path
  @path
end

#stateObject

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



34
35
36
# File 'lib/rmk/vfile.rb', line 34

def state
  @state
end

#vpathObject (readonly)

Returns the value of attribute vpath.



5
6
7
# File 'lib/rmk/vfile.rb', line 5

def vpath
  @vpath
end

Class Method Details

.generate_modified_id(path) ⇒ Object



8
# File 'lib/rmk/vfile.rb', line 8

def self.generate_modified_id(path) File.mtime(path).to_i end

Instance Method Details

#change_to_out!(outfile) ⇒ self

change to out file

Parameters:

Returns:

  • (self)


51
52
53
54
55
56
57
58
59
60
61
62
# 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_buildObject

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



70
71
72
73
74
75
# 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_parseObject

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



78
79
80
# File 'lib/rmk/vfile.rb', line 78

def check_for_parse
  load_modified_id != generate_modified_id
end

#generate_modified_idObject

generate file’s modified id from current disk content



37
# File 'lib/rmk/vfile.rb', line 37

def generate_modified_id; Rmk::VFile.generate_modified_id @path end

#input_ref_buildsObject

builds which include this file as input file



13
# File 'lib/rmk/vfile.rb', line 13

def input_ref_builds; @input_ref_builds end

#load_modified_idObject

load last time modified id from system database

Returns:

  • (Object)

    last stored modified id or nil for no last stored id



41
# File 'lib/rmk/vfile.rb', line 41

def load_modified_id; @rmk.mid_storage[@path] end

#order_ref_buildsObject

builds which include this file as order-only file



16
# File 'lib/rmk/vfile.rb', line 16

def order_ref_builds; @order_ref_builds end

#src?Boolean

Returns:

  • (Boolean)


10
# File 'lib/rmk/vfile.rb', line 10

def src?; @is_src end

#store_modified_id(mid) ⇒ Object

store modified id to system database for next time check

Parameters:

  • mid (Object)

    modified id

Returns:

  • (Object)

    stored modified id



46
# File 'lib/rmk/vfile.rb', line 46

def store_modified_id(mid) @rmk.mid_storage[@path] = mid end

#updated!(modified) ⇒ Object



64
65
66
67
# 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