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.



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

#membersObject (readonly)

All members (groups or syncs) of this group



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

def members
  @members
end

#nameObject (readonly)

The name of the group



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

def name
  @name
end

#parentObject (readonly)

The parent of the group



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

def parent
  @parent
end

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

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


108
109
110
# File 'lib/multisync/definition/entity.rb', line 108

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

#checksObject

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

Returns:

  • (Boolean)


98
99
100
# File 'lib/multisync/definition/entity.rb', line 98

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

#destinationObject

rsync destination



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

def destination
  @to_value || parent.destination
end

#destination_descriptionObject



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

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

#fullnameObject

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_optionsObject

rsync options



91
92
93
94
95
# File 'lib/multisync/definition/entity.rb', line 91

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

#sourceObject

rsync source



73
74
75
# File 'lib/multisync/definition/entity.rb', line 73

def source
  @from_value || parent.source
end

#source_descriptionObject



77
78
79
# File 'lib/multisync/definition/entity.rb', line 77

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

#to_hObject



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: rsync_options,
  }
end