Class: Rant::Generators::SignedFile

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/rant/import/signedfile.rb

Direct Known Subclasses

AutoSubSignedFile, SignedDirectory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Node

#inspect

Constructor Details

#initialize(rac, name, prerequisites, &block) ⇒ SignedFile

Returns a new instance of SignedFile.



26
27
28
29
30
31
32
33
34
35
# File 'lib/rant/import/signedfile.rb', line 26

def initialize(rac, name, prerequisites, &block)
    super()
    @rac = rac
    @name = name
    @pre = prerequisites or
        raise ArgumentError, "prerequisites required"
    @block = block
    @run = false
    @receiver = nil
end

Instance Attribute Details

#receiverObject

Returns the value of attribute receiver.



24
25
26
# File 'lib/rant/import/signedfile.rb', line 24

def receiver
  @receiver
end

Class Method Details

.rant_gen(rac, ch, args, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rant/import/signedfile.rb', line 15

def self.rant_gen(rac, ch, args, &block)
    unless args.size == 1
        rac.abort_at(ch, "SignedFile: too many arguments")
    end
    rac.prepare_task(args.first, block, ch) { |name,pre,blk|
        self.new(rac, name, pre, &blk)
    }
end

Instance Method Details

#<<(pre) ⇒ Object



50
51
52
# File 'lib/rant/import/signedfile.rb', line 50

def <<(pre)
    @pre << pre
end

#each_target {|@name| ... } ⇒ Object

Yields:

  • (@name)


128
129
130
131
# File 'lib/rant/import/signedfile.rb', line 128

def each_target
    goto_task_home
    yield @name
end

#enhance(deps = nil, &blk) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rant/import/signedfile.rb', line 59

def enhance(deps = nil, &blk)
    @pre.concat(deps) if deps
    if @block
        if blk
            first_block = @block
            @block = lambda { |t|
                first_block[t]
                blk[t]
            }
        end
    else
        @block = blk
    end
end

#fail?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rant/import/signedfile.rb', line 56

def fail?
    @success == false
end

#file_target?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rant/import/signedfile.rb', line 47

def file_target?
    true
end

#has_actions?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rant/import/signedfile.rb', line 44

def has_actions?
    @block or @receiver && @receiver.has_pre_action?
end

#invoke(opt = INVOKE_OPT) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rant/import/signedfile.rb', line 73

def invoke(opt = INVOKE_OPT)
    return circular_dep if @run
    @run = true
    begin
        return if done?
        goto_task_home
        @cur_checksums = []
        @sigs = @rac.var._get("__signature__")
        @md = @rac.var._get("__metadata__")
        key = "prerequisites_sig_#{@sigs.name}"
        target_key = "target_sig_#{@sigs.name}"
        up = signed_process_prerequisites(opt)
        up ||= opt[:force]
        up = true if @receiver && @receiver.update?(self)
        @cur_checksums.sort!
        check_str = @cur_checksums.join
        @cur_checksums = nil
        old_check_str = @md.path_fetch(key, @name)
        old_target_str = @md.path_fetch(target_key, @name)
        # check explicitely for plain file, thus allow the
        # target of a SignedFile to be a directory ;)
        if test(?f, @name)
            target_str = @sigs.signature_for_file(@name)
        else
            target_str = ""
            up ||= !File.exist?(@name)
        end
        check_str_changed = old_check_str != check_str
        target_changed = old_target_str != target_str
        up ||= check_str_changed || target_changed
        return up if opt[:needed?]
        return false unless up
        # run action and save checksums
        run
        goto_task_home
        target_str = test(?f, @name) ?
            @sigs.signature_for_file(@name) : ""
        target_changed = target_str != old_target_str
        if target_changed
            @md.path_set(target_key, target_str, @name)
        end
        if check_str_changed
            @md.path_set(key, check_str, @name)
        end
        @success = true
        return target_changed
    rescue TaskFail => e
        raise
    rescue Exception => e
        self.fail(nil, e)
    ensure
        @md = @sigs = nil
        @run = false
    end
end

#invoked?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/rant/import/signedfile.rb', line 53

def invoked?
    !@success.nil?
end

#prerequisitesObject Also known as: deps



36
37
38
# File 'lib/rant/import/signedfile.rb', line 36

def prerequisites
    @pre
end

#signatureObject



135
136
137
138
139
140
141
# File 'lib/rant/import/signedfile.rb', line 135

def signature
    goto_task_home
    sigs = @rac.var._get("__signature__")
    md = @rac.var._get("__metadata__")
    key = "target_sig_#{sigs.name}"
    md.path_fetch(key, @name)
end

#sourceObject

first prerequisite



41
42
43
# File 'lib/rant/import/signedfile.rb', line 41

def source
    @pre.first.to_s
end

#timestamp(opt = INVOKE_OPT) ⇒ Object



132
133
134
# File 'lib/rant/import/signedfile.rb', line 132

def timestamp(opt = INVOKE_OPT)
    File.exist?(@name) ? File.mtime(@name) : T0
end