Module: Cody::Core

Extended by:
Memoist
Included in:
Cody
Defined in:
lib/cody/core.rb

Instance Method Summary collapse

Instance Method Details

#check_cody_project!Object



47
48
49
50
51
52
53
54
55
# File 'lib/cody/core.rb', line 47

def check_cody_project!
  check_path = "#{Cody.root}/.cody"
  unless File.exist?(check_path)
    puts "ERROR: No .cody folder found.  Are you sure you are in a project with cody setup?".color(:red)
    puts "Current directory: #{Dir.pwd}"
    puts "If you want to set up cody for this project, please create a settings file via: cody init"
    exit 1 unless ENV['TEST']
  end
end

#envObject



13
14
15
16
17
18
# File 'lib/cody/core.rb', line 13

def env
  # 2-way binding
  cb_env = env_from_profile || 'development'
  cb_env = ENV['CODY_ENV'] if ENV['CODY_ENV'] # highest precedence
  ActiveSupport::StringInquirer.new(cb_env)
end

#extraObject



21
22
23
24
25
# File 'lib/cody/core.rb', line 21

def extra
  extra = ENV['CODY_EXTRA'] if ENV['CODY_EXTRA'] # highest precedence
  return if extra&.empty?
  extra
end

#rootObject



8
9
10
11
# File 'lib/cody/core.rb', line 8

def root
  path = ENV['CODY_ROOT'] || '.'
  Pathname.new(path)
end

#set_aws_profile!Object

Overrides AWS_PROFILE based on the Cody.env if set in configs/settings.yml 2-way binding.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cody/core.rb', line 30

def set_aws_profile!
  return if ENV['TEST']
  return unless File.exist?("#{Cody.root}/.cody/settings.yml") # for rake docs
  return unless settings # Only load if within Cody project and there's a settings.yml

  data = settings || {}
  if data[:aws_profile]
    puts "Using AWS_PROFILE=#{data[:aws_profile]} from CODY_ENV=#{Cody.env} in config/settings.yml"
    ENV['AWS_PROFILE'] = data[:aws_profile]
  end
end

#settingsObject



42
43
44
# File 'lib/cody/core.rb', line 42

def settings
  Setting.new.data
end