Class: Watchcat::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/watchcat/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kinds, paths, raw_kind) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
# File 'lib/watchcat/event.rb', line 7

def initialize(kinds, paths, raw_kind)
  @paths = paths
  @raw_kind = raw_kind
  build_kind(kinds)
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/watchcat/event.rb', line 5

def event
  @event
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/watchcat/event.rb', line 5

def kind
  @kind
end

#pathsObject (readonly)

Returns the value of attribute paths.



5
6
7
# File 'lib/watchcat/event.rb', line 5

def paths
  @paths
end

#raw_kindObject (readonly)

Returns the value of attribute raw_kind.



5
6
7
# File 'lib/watchcat/event.rb', line 5

def raw_kind
  @raw_kind
end

Instance Method Details

#deconstruct_keys(_keys) ⇒ Object



13
14
15
# File 'lib/watchcat/event.rb', line 13

def deconstruct_keys(_keys)
  { paths: @paths, event: @event }
end

#dest_pathObject



40
41
42
43
44
45
46
47
48
# File 'lib/watchcat/event.rb', line 40

def dest_path
  return nil unless rename_event?

  rename = kind.modify.rename
  return @paths[1] if rename.both?
  return @paths[0] if rename.to?

  nil
end

#directory?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watchcat/event.rb', line 17

def directory?
  if kind.create?
    kind.create.folder?
  elsif kind.remove?
    kind.remove.folder?
  elsif kind.any?
    kind.any.folder?
  else
    File.directory?(@paths.first)
  end
rescue
  false
end

#src_pathObject



31
32
33
34
35
36
37
38
# File 'lib/watchcat/event.rb', line 31

def src_path
  return nil unless rename_event?

  rename = kind.modify.rename
  return @paths[0] if rename.both? || rename.from?

  nil
end