Class: Gemchain::Config

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

Defined Under Namespace

Classes: NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace: Dir.pwd, include: [], exclude: [], gems: {}, bump: :patch) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
# File 'lib/gemchain/config.rb', line 11

def initialize(workspace: Dir.pwd, include: [], exclude: [], gems: {}, bump: :patch)
  @workspace = File.expand_path(workspace)
  @include_patterns = [include].flatten.compact
  @exclude_patterns = [exclude].flatten.compact
  @gems = gems
  @bump = (bump || :patch).to_sym
end

Instance Attribute Details

#bumpObject (readonly)

Returns the value of attribute bump.



9
10
11
# File 'lib/gemchain/config.rb', line 9

def bump
  @bump
end

#exclude_patternsObject (readonly)

Returns the value of attribute exclude_patterns.



9
10
11
# File 'lib/gemchain/config.rb', line 9

def exclude_patterns
  @exclude_patterns
end

#gemsObject (readonly)

Returns the value of attribute gems.



9
10
11
# File 'lib/gemchain/config.rb', line 9

def gems
  @gems
end

#include_patternsObject (readonly)

Returns the value of attribute include_patterns.



9
10
11
# File 'lib/gemchain/config.rb', line 9

def include_patterns
  @include_patterns
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



9
10
11
# File 'lib/gemchain/config.rb', line 9

def workspace
  @workspace
end

Class Method Details

.load(path) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gemchain/config.rb', line 19

def self.load(path)
  path = File.expand_path(path)
  raise NotFoundError, "Config file not found: #{path}" unless File.exist?(path)

  data = YAML.safe_load(File.read(path), permitted_classes: [Regexp]) || {}
  new(
    workspace: data["workspace"] || Dir.pwd,
    include: data["include"] || [],
    exclude: data["exclude"] || [],
    gems: data["gems"] || {},
    bump: data["bump"] || :patch
  )
end

Instance Method Details

#gem_dirsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gemchain/config.rb', line 33

def gem_dirs
  if @gems.any?
    @gems.values.map { |g| File.expand_path(g, @workspace) }
  else
    dirs = Dir.glob(@include_patterns, base: @workspace).select do |entry|
      full_path = File.join(@workspace, entry)
      File.directory?(full_path) && gemspec_in?(full_path)
    end.map { |entry| File.join(@workspace, entry) }

    if @exclude_patterns.any?
      excluded = Dir.glob(@exclude_patterns, base: @workspace).map { |e| File.join(@workspace, e) }
      dirs -= excluded
    end

    dirs
  end
end