Class: HerokuSan::Project

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/heroku_san/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Git

#git_active_branch, #git_clone, #git_named_rev, #git_parsed_tag, #git_push, #git_rev_parse, #git_revision, #git_tag

Constructor Details

#initialize(config_file = nil, options = {}) ⇒ Project

Returns a new instance of Project.



8
9
10
11
12
# File 'lib/heroku_san/project.rb', line 8

def initialize(config_file = nil, options = {})
  @config_file = config_file
  @options = options
  @apps = []
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



4
5
6
# File 'lib/heroku_san/project.rb', line 4

def config_file
  @config_file
end

#configurationObject



18
19
20
# File 'lib/heroku_san/project.rb', line 18

def configuration
  @configuration ||= HerokuSan::Configuration.new(self)
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/heroku_san/project.rb', line 5

def options
  @options
end

Instance Method Details

#<<(*app) ⇒ Object



34
35
36
37
38
39
# File 'lib/heroku_san/project.rb', line 34

def <<(*app)
  app.flatten.each do |a|
    @apps << a if all.include?(a)
  end
  self
end

#[](stage) ⇒ Object



30
31
32
# File 'lib/heroku_san/project.rb', line 30

def [](stage)
  stages[stage]
end

#allObject



26
27
28
# File 'lib/heroku_san/project.rb', line 26

def all
  stages.keys
end

#appsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/heroku_san/project.rb', line 41

def apps
  if @apps && !@apps.empty?
    @apps
  else
    @apps = if all.size == 1
      $stdout.puts "Defaulting to #{all.first.inspect} since only one app is defined"
      all
    else
      active_branch = self.git_active_branch
      all.select do |app|
        app == active_branch and ($stdout.puts("Defaulting to '#{app}' as it matches the current branch"); true)
      end
    end
  end
end

#create_configObject



22
23
24
# File 'lib/heroku_san/project.rb', line 22

def create_config
  HerokuSan::Configuration.new(self).generate_config
end

#each_appObject

Raises:



57
58
59
60
61
62
63
# File 'lib/heroku_san/project.rb', line 57

def each_app
  raise NoApps if apps.empty?
  HerokuSan::Parser.new.merge_external_config!(configuration, stages.values)
  apps.each do |stage|
    yield self[stage]
  end
end

#stagesObject



14
15
16
# File 'lib/heroku_san/project.rb', line 14

def stages
  @stages ||= configuration.stages
end