Module: Propro::Package

Defined in:
lib/propro/package.rb

Constant Summary collapse

EXTRACT_NAME_RE =
%r{/ext/bash/([a-z0-9_\-/]+)\.sh}
SORTED_NAMES =
%w[
  lib/propro
  lib/ubuntu
  lib/system
  lib/pg
  lib/rvm
  lib/nginx
  lib/node
  lib/redis
  vps/system
  app
  app/rvm
  app/pg
  app/nginx
  app/sidekiq
  app/monit
  app/puma
  app/puma/nginx
  app/node
  app/unicorn
  app/unicorn/nginx
  app/unicorn/monit
  db/pg
  db/redis
  vagrant
  vagrant/system
  vagrant/pg
  vagrant/redis
  vagrant/rvm
  vagrant/node
  vagrant/nginx
  lib/extras
]

Class Method Summary collapse

Class Method Details

.resort!(ary) ⇒ Object



67
68
69
70
# File 'lib/propro/package.rb', line 67

def resort!(ary)
  ary.sort_by! { |source| SORTED_NAMES.index(source.name) }
  ary
end

.rootObject



40
41
42
# File 'lib/propro/package.rb', line 40

def root
  File.join(Propro.root, 'ext/bash')
end

.source_filesObject



44
45
46
# File 'lib/propro/package.rb', line 44

def source_files
  @source_files ||= Dir[File.join(root, '**/*.sh')]
end

.sourcesObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/propro/package.rb', line 48

def sources
  @sources ||= begin
    names = SORTED_NAMES.dup
    source_files.each do |file|
      name = EXTRACT_NAME_RE.match(file)[1]
      names.push(name) unless names.include?(name)
    end
    names.map { |name| Source.new(name) }
  end
end

.sources_for_path(path) ⇒ Object



59
60
61
# File 'lib/propro/package.rb', line 59

def sources_for_path(path)
  resort! sources.select { |source| /\A#{path}/ =~ source.name }
end

.sources_for_paths(*paths) ⇒ Object



63
64
65
# File 'lib/propro/package.rb', line 63

def sources_for_paths(*paths)
  resort! paths.flatten.map { |path| sources_for_path(path) }.flatten
end