Class: LogicalConstruct::ResolutionServer::States::PlanState

Inherits:
Object
  • Object
show all
Includes:
FileTest, Protocol::PlanValidation
Defined in:
lib/logical-construct/target/plan-records.rb

Direct Known Subclasses

Resolved, Resolving, Unresolved

Constant Summary

Constants included from Protocol::PlanValidation

Protocol::PlanValidation::BIG_CHUNK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Protocol::PlanValidation

#check_digest, #chunk_size, #digest, #file_checksum, #generate_checksum, #realpath

Constructor Details

#initialize(records, record) ⇒ PlanState

Returns a new instance of PlanState.



88
89
90
# File 'lib/logical-construct/target/plan-records.rb', line 88

def initialize(records, record)
  @records, @record = records, record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



91
92
93
# File 'lib/logical-construct/target/plan-records.rb', line 91

def record
  @record
end

Instance Method Details

#==(other) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/logical-construct/target/plan-records.rb', line 97

def ==(other)
  return true if self.equal?(other)
  return false if !self.alive? or !other.alive?
  return (other.class.equal?(self.class) and
          other.name.equal?(self.name) and
          other.filehash.equal?(self.filehash))
end

#alive?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/logical-construct/target/plan-records.rb', line 123

def alive?
  !@record.nil?
end

#can_receive?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/logical-construct/target/plan-records.rb', line 147

def can_receive?
  false
end

#cancel!Object



119
120
121
# File 'lib/logical-construct/target/plan-records.rb', line 119

def cancel!
  @record = nil
end

#change(next_state) ⇒ Object



151
152
153
# File 'lib/logical-construct/target/plan-records.rb', line 151

def change(next_state)
  @records.change(self, next_state)
end

#current_pathObject



163
164
165
# File 'lib/logical-construct/target/plan-records.rb', line 163

def current_path
  @current_path ||= Pathname.new(current_plans_dir) + name
end

#current_plans_dirObject



135
136
137
# File 'lib/logical-construct/target/plan-records.rb', line 135

def current_plans_dir
  @records.directories.current
end

#delivered_plans_dirObject



131
132
133
# File 'lib/logical-construct/target/plan-records.rb', line 131

def delivered_plans_dir
  @records.directories.delivered
end

#enterObject



116
117
# File 'lib/logical-construct/target/plan-records.rb', line 116

def enter
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/logical-construct/target/plan-records.rb', line 127

def exists?(path)
  super(realpath(path))
end

#filehashObject



111
112
113
114
# File 'lib/logical-construct/target/plan-records.rb', line 111

def filehash
  return nil unless alive?
  @record.filehash
end

#inspectObject



93
94
95
# File 'lib/logical-construct/target/plan-records.rb', line 93

def inspect
  "#<#{self.class.name}:#{"0x%0x"%object_id} #{name||"dead"}:#{filehash}>"
end

#joinObject



179
180
181
# File 'lib/logical-construct/target/plan-records.rb', line 179

def join
  return
end

#nameObject



106
107
108
109
# File 'lib/logical-construct/target/plan-records.rb', line 106

def name
  return nil unless alive?
  @record.name
end

#receiveObject



171
172
173
# File 'lib/logical-construct/target/plan-records.rb', line 171

def receive
  warn "Cannot receive file in current state: #{state}"
end

#received_pathObject



155
156
157
# File 'lib/logical-construct/target/plan-records.rb', line 155

def received_path
  @received_path ||= Pathname.new(delivered_plans_dir) + name
end

#resolveObject



167
168
169
# File 'lib/logical-construct/target/plan-records.rb', line 167

def resolve
  warn "Cannot resolve plan in current state: #{state}"
end

#resolved?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/logical-construct/target/plan-records.rb', line 143

def resolved?
  false
end

#stateObject



175
176
177
# File 'lib/logical-construct/target/plan-records.rb', line 175

def state
  self.class.name.sub(/.*::/,'').downcase
end

#storage_path_for(actual_hash) ⇒ Object



159
160
161
# File 'lib/logical-construct/target/plan-records.rb', line 159

def storage_path_for(actual_hash)
  @stored_path ||= Pathname.new(stored_plans_dir) + [name, actual_hash].join(".")
end

#stored_plans_dirObject



139
140
141
# File 'lib/logical-construct/target/plan-records.rb', line 139

def stored_plans_dir
  @records.directories.stored
end