Class: Entangler::EntangledFile

Inherits:
Object
  • Object
show all
Defined in:
lib/entangler/entangled_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, rel_path) ⇒ EntangledFile

Returns a new instance of EntangledFile.



10
11
12
13
14
15
# File 'lib/entangler/entangled_file.rb', line 10

def initialize(action, rel_path)
  @action = action
  @path = rel_path
  @desired_modtime = Time.now.to_i
  @contents = nil
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



7
8
9
# File 'lib/entangler/entangled_file.rb', line 7

def action
  @action
end

#contentsObject (readonly)

Returns the value of attribute contents.



8
9
10
# File 'lib/entangler/entangled_file.rb', line 8

def contents
  @contents
end

#desired_modtimeObject

Returns the value of attribute desired_modtime.



7
8
9
# File 'lib/entangler/entangled_file.rb', line 7

def desired_modtime
  @desired_modtime
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/entangler/entangled_file.rb', line 8

def path
  @path
end

Instance Method Details

#file_exists?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/entangler/entangled_file.rb', line 21

def file_exists?
  File.exist?(full_path)
end

#full_pathObject



17
18
19
# File 'lib/entangler/entangled_file.rb', line 17

def full_path
  Entangler.executor.generate_abs_path(@path)
end

#processObject



25
26
27
28
29
30
31
32
# File 'lib/entangler/entangled_file.rb', line 25

def process
  if action == :create || action == :update
    create_parent_directory
    write_contents
  elsif action == :delete
    delete_file
  end
end