Class: Multisync::Definition::Entity
- Inherits:
-
Object
- Object
- Multisync::Definition::Entity
- Includes:
- Dsl
- Defined in:
- lib/multisync/definition/entity.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
The level of the entity.
-
#members ⇒ Object
readonly
All members (groups or syncs) of this entity.
-
#name ⇒ Object
readonly
The name of the entity.
-
#parent ⇒ Object
readonly
The parent of the entity.
-
#result ⇒ Object
readonly
Collected result after run { cmd: ‘rsync –stats -v source destination’, action: :run, status: #<Process::Status: pid 65416 exit 0>, stdout: ”, stderr: ”, skip_message: ‘host not reachable’, }.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Make the definition visitable.
-
#check_destination? ⇒ Boolean
Should destination’s host or path be checked before sync?.
-
#check_source? ⇒ Boolean
Should source’s host or path be checked before sync?.
-
#checks ⇒ Object
All checks from parent to child.
-
#default? ⇒ Boolean
Is this group/sync defined as default.
-
#destination ⇒ Object
rsync destination.
- #destination_description ⇒ Object
- #executeable? ⇒ Boolean
-
#fullname ⇒ Object
The name including all parents separated by “/”.
-
#initialize(parent, name, &block) ⇒ Entity
constructor
A new instance of Entity.
- #register(member) ⇒ Object
-
#rsync_options ⇒ Object
rsync options.
-
#source ⇒ Object
rsync source.
- #source_description ⇒ Object
Methods included from Dsl
#check_from, #check_to, #default, #from, #group, #include, #only_if, #options, #sync, #template, #to
Constructor Details
#initialize(parent, name, &block) ⇒ Entity
Returns a new instance of Entity.
28 29 30 31 32 33 34 35 36 |
# File 'lib/multisync/definition/entity.rb', line 28 def initialize parent, name, &block @members = [] @name = name @parent = parent @level = parent.level + 1 parent.register self instance_eval(&block) if block_given? @result = {} end |
Instance Attribute Details
#level ⇒ Object (readonly)
The level of the entity
11 12 13 |
# File 'lib/multisync/definition/entity.rb', line 11 def level @level end |
#members ⇒ Object (readonly)
All members (groups or syncs) of this entity
14 15 16 |
# File 'lib/multisync/definition/entity.rb', line 14 def members @members end |
#name ⇒ Object (readonly)
The name of the entity
8 9 10 |
# File 'lib/multisync/definition/entity.rb', line 8 def name @name end |
#parent ⇒ Object (readonly)
The parent of the entity
5 6 7 |
# File 'lib/multisync/definition/entity.rb', line 5 def parent @parent end |
#result ⇒ Object (readonly)
Collected result after run
{
cmd: 'rsync --stats -v source destination',
action: :run,
status: #<Process::Status: pid 65416 exit 0>,
stdout: '',
stderr: '',
skip_message: 'host not reachable',
}
26 27 28 |
# File 'lib/multisync/definition/entity.rb', line 26 def result @result end |
Instance Method Details
#accept(visitor) ⇒ Object
Make the definition visitable
39 40 41 42 43 44 |
# File 'lib/multisync/definition/entity.rb', line 39 def accept visitor visitor.visit self members.map do |member| member.accept visitor end end |
#check_destination? ⇒ Boolean
Should destination’s host or path be checked before sync?
100 101 102 |
# File 'lib/multisync/definition/entity.rb', line 100 def check_destination? @to_check.nil? ? parent.check_destination? : @to_check end |
#check_source? ⇒ Boolean
Should source’s host or path be checked before sync?
95 96 97 |
# File 'lib/multisync/definition/entity.rb', line 95 def check_source? @from_check.nil? ? parent.check_source? : @from_check end |
#checks ⇒ Object
All checks from parent to child
90 91 92 |
# File 'lib/multisync/definition/entity.rb', line 90 def checks (parent.checks + [@check]).compact end |
#default? ⇒ Boolean
Is this group/sync defined as default
81 82 83 |
# File 'lib/multisync/definition/entity.rb', line 81 def default? @default || parent.default? end |
#destination ⇒ Object
rsync destination
65 66 67 |
# File 'lib/multisync/definition/entity.rb', line 65 def destination @to_value || parent.destination end |
#destination_description ⇒ Object
69 70 71 |
# File 'lib/multisync/definition/entity.rb', line 69 def destination_description @to_description || @to_value || parent.destination_description end |
#executeable? ⇒ Boolean
85 86 87 |
# File 'lib/multisync/definition/entity.rb', line 85 def executeable? members.none? end |
#fullname ⇒ Object
The name including all parents separated by “/”
51 52 53 |
# File 'lib/multisync/definition/entity.rb', line 51 def fullname [parent.fullname, name].reject(&:empty?).join("/") end |
#register(member) ⇒ Object
46 47 48 |
# File 'lib/multisync/definition/entity.rb', line 46 def register member members << member end |
#rsync_options ⇒ Object
rsync options
74 75 76 77 78 |
# File 'lib/multisync/definition/entity.rb', line 74 def opts = || [] return opts if == :override parent. + opts end |
#source ⇒ Object
rsync source
56 57 58 |
# File 'lib/multisync/definition/entity.rb', line 56 def source @from_value || parent.source end |
#source_description ⇒ Object
60 61 62 |
# File 'lib/multisync/definition/entity.rb', line 60 def source_description @from_description || @from_value || parent.source_description end |