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
-
#members ⇒ Object
readonly
All members (groups or syncs) of this group.
-
#name ⇒ Object
readonly
The name of the group.
-
#parent ⇒ Object
readonly
The parent of the group.
-
#result ⇒ Object
readonly
Collected results after run as Hash { 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, level = 0) ⇒ 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
-
#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
- #to_h ⇒ 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.
27 28 29 30 31 32 33 34 |
# File 'lib/multisync/definition/entity.rb', line 27 def initialize parent, name, &block @members = [] @name = name.to_s @parent = parent parent.register self instance_eval(&block) if block_given? @result = {} end |
Instance Attribute Details
#members ⇒ Object (readonly)
All members (groups or syncs) of this group
13 14 15 |
# File 'lib/multisync/definition/entity.rb', line 13 def members @members end |
#name ⇒ Object (readonly)
The name of the group
10 11 12 |
# File 'lib/multisync/definition/entity.rb', line 10 def name @name end |
#parent ⇒ Object (readonly)
The parent of the group
7 8 9 |
# File 'lib/multisync/definition/entity.rb', line 7 def parent @parent end |
#result ⇒ Object (readonly)
Collected results after run as Hash
{
cmd: 'rsync --stats -v source destination',
action: :run,
status: #<Process::Status: pid 65416 exit 0>,
stdout: '',
stderr: '',
skip_message: 'host not reachable',
}
25 26 27 |
# File 'lib/multisync/definition/entity.rb', line 25 def result @result end |
Instance Method Details
#accept(visitor, level = 0) ⇒ Object
Make the definition visitable
56 57 58 59 60 61 |
# File 'lib/multisync/definition/entity.rb', line 56 def accept visitor, level=0 visitor.visit self, level members.map do |member| member.accept visitor, level+1 end end |
#check_destination? ⇒ Boolean
Should destination’s host or path be checked before sync?
113 114 115 |
# File 'lib/multisync/definition/entity.rb', line 113 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?
108 109 110 |
# File 'lib/multisync/definition/entity.rb', line 108 def check_source? @from_check.nil? ? parent.check_source? : @from_check end |
#checks ⇒ Object
All checks from parent to child
103 104 105 |
# File 'lib/multisync/definition/entity.rb', line 103 def checks (parent.checks + [@check]).compact end |
#default? ⇒ Boolean
Is this group/sync defined as default
98 99 100 |
# File 'lib/multisync/definition/entity.rb', line 98 def default? @default || parent.default? end |
#destination ⇒ Object
rsync destination
82 83 84 |
# File 'lib/multisync/definition/entity.rb', line 82 def destination @to_value || parent.destination end |
#destination_description ⇒ Object
86 87 88 |
# File 'lib/multisync/definition/entity.rb', line 86 def destination_description @to_description || @to_value || parent.destination_description end |
#fullname ⇒ Object
The name including all parents separated by “/”
68 69 70 |
# File 'lib/multisync/definition/entity.rb', line 68 def fullname [parent.fullname, name].join '/' end |
#register(member) ⇒ Object
63 64 65 |
# File 'lib/multisync/definition/entity.rb', line 63 def register member members << member end |
#rsync_options ⇒ Object
rsync options
91 92 93 94 95 |
# File 'lib/multisync/definition/entity.rb', line 91 def opts = @rsync_options || [] return opts if @rsync_options_mode == :override parent. + opts end |
#source ⇒ Object
rsync source
73 74 75 |
# File 'lib/multisync/definition/entity.rb', line 73 def source @from_value || parent.source end |
#source_description ⇒ Object
77 78 79 |
# File 'lib/multisync/definition/entity.rb', line 77 def source_description @from_description || @from_value || parent.source_description end |
#to_h ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/multisync/definition/entity.rb', line 36 def to_h { fullname: fullname, default: default?, source: { path: source, description: source_description, check: check_source?, }, destination: { path: destination, description: destination_description, check: check_destination?, }, checks: checks, rsync_options: , } end |