Class: Deployme::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/deployme/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Options



5
6
7
8
9
10
11
# File 'lib/deployme/options.rb', line 5

def initialize(hash)
  @data = OpenStruct.new(hash)

  # Set defaults
  @data.name ||= File.basename(File.expand_path('.'))
  @data.directory ||= File.expand_path('.deploy')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



41
42
43
# File 'lib/deployme/options.rb', line 41

def method_missing(meth, *args, &blk)
  @data.send(meth, *args, &blk)
end

Instance Method Details

#change_idObject



21
22
23
# File 'lib/deployme/options.rb', line 21

def change_id
  @data.change_id ||= ENV.fetch('CHANGE_ID', nil)
end

#deploy_hostObject



33
34
35
# File 'lib/deployme/options.rb', line 33

def deploy_host
  @data.deploy_host ||= "#{deploy_name}.#{@data.deploy_domain}"
end

#deploy_nameObject



25
26
27
28
29
30
31
# File 'lib/deployme/options.rb', line 25

def deploy_name
  @deploy_name ||= if change_id
                     "#{@data.name}-pr-#{change_id}"
                   else
                     @data.name
  end
end

#deploy_urlObject



37
38
39
# File 'lib/deployme/options.rb', line 37

def deploy_url
  @data.deploy_url ||= "https://#{deploy_host}"
end

#git_branchObject



17
18
19
# File 'lib/deployme/options.rb', line 17

def git_branch
  @data.git_branch ||= ENV.fetch('GIT_BRANCH') { `git rev-parse HEAD | git branch -a --contains | sed -n 2p | cut -d'/' -f 3-`.strip }
end

#git_commitObject



13
14
15
# File 'lib/deployme/options.rb', line 13

def git_commit
  @data.git_commit ||= ENV.fetch('GIT_COMMIT') { `git rev-parse HEAD`.strip }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean



45
46
47
# File 'lib/deployme/options.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  @data.respond_to?(method_name, include_private) || super
end