Class: Mclone::Task
- Inherits:
-
Object
- Object
- Mclone::Task
- Defined in:
- lib/mclone.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MODES =
[:update, :synchronize, :copy, :move].freeze
Instance Attribute Summary collapse
-
#destination_id ⇒ Object
readonly
Returns the value of attribute destination_id.
-
#destination_root ⇒ Object
readonly
Returns the value of attribute destination_root.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#include ⇒ Object
Returns the value of attribute include.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#source_id ⇒ Object
readonly
Returns the value of attribute source_id.
-
#source_root ⇒ Object
readonly
Returns the value of attribute source_root.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(source_id, source_root, destination_id, destination_root) ⇒ Task
constructor
A new instance of Task.
- #to_h ⇒ Object
- #touch! ⇒ Object
Constructor Details
#initialize(source_id, source_root, destination_id, destination_root) ⇒ Task
Returns a new instance of Task.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/mclone.rb', line 175 def initialize(source_id, source_root, destination_id, destination_root) @touch = false # Indicates that the time stamp should be updated whenever state of self is altered @id = SecureRandom.hex(4) @source_id = source_id @destination_id = destination_id @source_root = source_root @destination_root = destination_root self.mode = :update self.include = '**' self.exclude = '' ensure @touch = true touch! end |
Instance Attribute Details
#destination_id ⇒ Object (readonly)
Returns the value of attribute destination_id.
145 146 147 |
# File 'lib/mclone.rb', line 145 def destination_id @destination_id end |
#destination_root ⇒ Object (readonly)
Returns the value of attribute destination_root.
148 149 150 |
# File 'lib/mclone.rb', line 148 def destination_root @destination_root end |
#exclude ⇒ Object
Returns the value of attribute exclude.
157 158 159 |
# File 'lib/mclone.rb', line 157 def exclude @exclude end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
142 143 144 |
# File 'lib/mclone.rb', line 142 def id @id end |
#include ⇒ Object
Returns the value of attribute include.
157 158 159 |
# File 'lib/mclone.rb', line 157 def include @include end |
#mode ⇒ Object
Returns the value of attribute mode.
154 155 156 |
# File 'lib/mclone.rb', line 154 def mode @mode end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
151 152 153 |
# File 'lib/mclone.rb', line 151 def mtime @mtime end |
#source_id ⇒ Object (readonly)
Returns the value of attribute source_id.
145 146 147 |
# File 'lib/mclone.rb', line 145 def source_id @source_id end |
#source_root ⇒ Object (readonly)
Returns the value of attribute source_root.
148 149 150 |
# File 'lib/mclone.rb', line 148 def source_root @source_root end |
Class Method Details
.restore(hash) ⇒ Object
218 219 220 221 222 |
# File 'lib/mclone.rb', line 218 def self.restore(hash) obj = allocate obj.send(:from_h, hash) obj end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
163 164 165 166 167 168 169 170 |
# File 'lib/mclone.rb', line 163 def eql?(other) equal?(other) || ( source_id == other.source_id && destination_id == other.destination_id && source_root == other.source_root && destination_root == other.destination_root ) end |
#hash ⇒ Object
159 160 161 |
# File 'lib/mclone.rb', line 159 def hash @hash ||= source_id.hash ^ destination_id.hash ^ source_root.hash ^ destination_root.hash end |
#to_h ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/mclone.rb', line 239 def to_h { mode: mode, include: include, exclude: exclude, task: id, source: {volume: source_id, root: source_root}, destination: {volume: destination_id, root: destination_root}, mtime: mtime } end |
#touch! ⇒ Object
252 253 254 |
# File 'lib/mclone.rb', line 252 def touch! @mtime = DateTime.now if @touch end |