Class: Trout::ManagedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/trout/managed_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ManagedFile

Returns a new instance of ManagedFile.



7
8
9
10
11
12
# File 'lib/trout/managed_file.rb', line 7

def initialize(attributes)
  self.filename    = attributes[:filename]
  self.git_url     = attributes[:git_url]
  self.version     = attributes[:version]
  self.source_root = attributes[:source_root] || '/'
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/trout/managed_file.rb', line 5

def filename
  @filename
end

#git_urlObject

Returns the value of attribute git_url.



5
6
7
# File 'lib/trout/managed_file.rb', line 5

def git_url
  @git_url
end

#latest_versionObject

Returns the value of attribute latest_version.



5
6
7
# File 'lib/trout/managed_file.rb', line 5

def latest_version
  @latest_version
end

#source_rootObject

Returns the value of attribute source_root.



5
6
7
# File 'lib/trout/managed_file.rb', line 5

def source_root
  @source_root
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/trout/managed_file.rb', line 5

def version
  @version
end

Instance Method Details

#checkoutObject



14
15
16
17
18
19
20
# File 'lib/trout/managed_file.rb', line 14

def checkout
  clone_repository
  copy_to_destination
  puts "Checked out #{filename} from #{git_url}."
ensure
  cleanup
end

#to_hashObject



34
35
36
37
38
39
# File 'lib/trout/managed_file.rb', line 34

def to_hash
  { :filename    => filename,
    :git_url     => git_url,
    :version     => version,
    :source_root => source_root }
end

#updateObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trout/managed_file.rb', line 22

def update
  clone_repository
  if up_to_date?
    puts "#{filename} already up to date."
  else
    merge_to_destination
    puts "Merged changes to #{filename}."
  end
ensure
  cleanup
end