Class: Githack::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/githack/repository.rb

Constant Summary collapse

SECRET_PATH =

Represent the path to secrets files

[].freeze
DATABASE_PATH =

Represent the path to database configuration files

[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote) ⇒ Repository

Returns a new instance of Repository.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/githack/repository.rb', line 15

def initialize(remote)
  @remote = remote
  @name = remote.gsub /[^0-9A-Z]/i, '_'
  @path = File.join(Dir.tmpdir, name)

  @git = if File.directory? @path
           Git.open @path
         else
           Git.clone @remote, @name, path: Dir.tmpdir
         end
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



8
9
10
# File 'lib/githack/repository.rb', line 8

def git
  @git
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/githack/repository.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/githack/repository.rb', line 8

def path
  @path
end

#remoteObject (readonly)

Returns the value of attribute remote.



8
9
10
# File 'lib/githack/repository.rb', line 8

def remote
  @remote
end

Instance Method Details

#databasesArray<Githack::Leak>

Get all changements for config/database.yml file (who contains database configuration for Ruby on Rails Framework)

Returns:



44
45
46
47
48
49
50
51
52
53
# File 'lib/githack/repository.rb', line 44

def databases
  leaks = []
  files = self.class::DATABASE_PATHS.map { |f| File.join(@path, f) }

  get_leaks(*files).each do |leak|
    leaks << leak
    yield lead if block_given?
  end
  leaks
end

#secretsArray<Githack::Leak>

Get all changements for config/secrets.yml file (who contains some API keys)

Returns:



30
31
32
33
34
35
36
37
38
39
# File 'lib/githack/repository.rb', line 30

def secrets
  leaks = []
  files = self.class::SECRET_PATHS.map { |f| File.join(@path, f) }

  get_leaks(*files).each do |leak|
    leaks << leak
    yield lead if block_given?
  end
  leaks
end