Class: Multisync::Definition::Entity

Inherits:
Object
  • Object
show all
Includes:
Dsl
Defined in:
lib/multisync/definition/entity.rb

Direct Known Subclasses

Null

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#levelObject (readonly)

The level of the entity



11
12
13
# File 'lib/multisync/definition/entity.rb', line 11

def level
  @level
end

#membersObject (readonly)

All members (groups or syncs) of this entity



14
15
16
# File 'lib/multisync/definition/entity.rb', line 14

def members
  @members
end

#nameObject (readonly)

The name of the entity



8
9
10
# File 'lib/multisync/definition/entity.rb', line 8

def name
  @name
end

#parentObject (readonly)

The parent of the entity



5
6
7
# File 'lib/multisync/definition/entity.rb', line 5

def parent
  @parent
end

#resultObject (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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


95
96
97
# File 'lib/multisync/definition/entity.rb', line 95

def check_source?
  @from_check.nil? ? parent.check_source? : @from_check
end

#checksObject

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

Returns:

  • (Boolean)


81
82
83
# File 'lib/multisync/definition/entity.rb', line 81

def default?
  @default || parent.default?
end

#destinationObject

rsync destination



65
66
67
# File 'lib/multisync/definition/entity.rb', line 65

def destination
  @to_value || parent.destination
end

#destination_descriptionObject



69
70
71
# File 'lib/multisync/definition/entity.rb', line 69

def destination_description
  @to_description || @to_value || parent.destination_description
end

#executeable?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/multisync/definition/entity.rb', line 85

def executeable?
  members.none?
end

#fullnameObject

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_optionsObject

rsync options



74
75
76
77
78
# File 'lib/multisync/definition/entity.rb', line 74

def rsync_options
  opts = @rsync_options || []
  return opts if @rsync_options_mode == :override
  parent.rsync_options + opts
end

#sourceObject

rsync source



56
57
58
# File 'lib/multisync/definition/entity.rb', line 56

def source
  @from_value || parent.source
end

#source_descriptionObject



60
61
62
# File 'lib/multisync/definition/entity.rb', line 60

def source_description
  @from_description || @from_value || parent.source_description
end