Class: Inch::Config::Codebase

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/config/codebase.rb

Overview

Stores the configuration for an individual single codebase

Constant Summary collapse

YAML_FILE =
".inch.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(included = nil, excluded = nil) ⇒ Codebase

Returns a new instance of Codebase.



10
11
12
13
# File 'lib/inch/config/codebase.rb', line 10

def initialize(included = nil, excluded = nil)
  @included_files = included || []
  @excluded_files = excluded || []
end

Instance Attribute Details

#excluded_filesObject (readonly)

Returns the value of attribute excluded_files.



6
7
8
# File 'lib/inch/config/codebase.rb', line 6

def excluded_files
  @excluded_files
end

#included_filesObject (readonly)

Returns the value of attribute included_files.



5
6
7
# File 'lib/inch/config/codebase.rb', line 5

def included_files
  @included_files
end

Class Method Details

.yaml(dir) ⇒ Hash?

Returns the contents of dir/.inch.yml, if present. Returns nil otherwise.

Parameters:

  • dir (String)

Returns:

  • (Hash, nil)


20
21
22
23
# File 'lib/inch/config/codebase.rb', line 20

def self.yaml(dir)
  yaml_file = File.join(dir, YAML_FILE)
  YAML.load(File.read(yaml_file)) if File.exist?(yaml_file)
end

Instance Method Details

#exclude_files(*files) ⇒ Object



41
42
43
# File 'lib/inch/config/codebase.rb', line 41

def exclude_files(*files)
  @excluded_files.concat(files).flatten!
end

#include_files(*files) ⇒ Object



37
38
39
# File 'lib/inch/config/codebase.rb', line 37

def include_files(*files)
  @included_files.concat(files).flatten!
end

#update(&block) ⇒ Object



25
26
27
# File 'lib/inch/config/codebase.rb', line 25

def update(&block)
  instance_eval(&block)
end

#update_via_yaml(dir) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/inch/config/codebase.rb', line 29

def update_via_yaml(dir)
  if yaml = self.class.yaml(dir)
    Dir.chdir(dir) do
      update_files yaml["files"]
    end
  end
end