Class: Gitignores::GitignoreFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gitignores/fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_repository, remote_repository) ⇒ GitignoreFetcher

Returns a new instance of GitignoreFetcher.



9
10
11
12
13
14
# File 'lib/gitignores/fetcher.rb', line 9

def initialize(local_repository, remote_repository)
  @local_repository = local_repository
  @remote_repository = remote_repository
  @update_ignores = false
  @git = Git.new
end

Instance Attribute Details

#git=(value) ⇒ Object (writeonly)

Sets the attribute git

Parameters:

  • value

    the value to set the attribute git to.



7
8
9
# File 'lib/gitignores/fetcher.rb', line 7

def git=(value)
  @git = value
end

#local_repository=(value) ⇒ Object (writeonly)

Sets the attribute local_repository

Parameters:

  • value

    the value to set the attribute local_repository to.



7
8
9
# File 'lib/gitignores/fetcher.rb', line 7

def local_repository=(value)
  @local_repository = value
end

#remote_repository=(value) ⇒ Object (writeonly)

Sets the attribute remote_repository

Parameters:

  • value

    the value to set the attribute remote_repository to.



7
8
9
# File 'lib/gitignores/fetcher.rb', line 7

def remote_repository=(value)
  @remote_repository = value
end

#update_ignores=(value) ⇒ Object (writeonly)

Sets the attribute update_ignores

Parameters:

  • value

    the value to set the attribute update_ignores to.



7
8
9
# File 'lib/gitignores/fetcher.rb', line 7

def update_ignores=(value)
  @update_ignores = value
end

Instance Method Details

#fetch_gitignoresObject

If needed, retrieves gitignores from Github and places them in @local_repository If @update_ignores? is set, will try to update the latest gitignores Will store all gitignores in the @local_repository



19
20
21
22
23
24
25
26
# File 'lib/gitignores/fetcher.rb', line 19

def fetch_gitignores()
  unless (Dir.exist?(@local_repository))
    @git.clone @remote_repository, @local_repository
  end
  if @update_ignores
    @git.pull @local_repository
  end
end

#list_gitignoresObject



28
29
30
31
32
33
34
# File 'lib/gitignores/fetcher.rb', line 28

def list_gitignores()
  fetch_gitignores

  Dir.glob(@local_repository + "/**/*.gitignore").collect { |x| 
    File.basename x, ".gitignore"
  }
end