Class: Jets::Core::Config::Project

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/core/config/project.rb

Overview

Intentionally keep this class simple. Frameworks should do the heavy lifting.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#config, #configure

Methods included from Util::Camelize

#camelize

Constructor Details

#initializeProject

Returns a new instance of Project.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jets/core/config/project.rb', line 13

def initialize(*)
  @autoload_paths = Set.new(%w[
    app/events
    app/extensions
    shared/resources
    shared/extensions
  ])
  @ignore_paths = Set.new(%w[
    app/functions
    shared/functions
  ])
  # Jets does not implement the concept of eager_load_paths like Rails for simplicity.
  # Also Jets always does an eager load of app code that it manages above.
  # This is because shared/extensions and shared/resources needed to be defined
  # early to generate the CloudFormation templates.

  @dotenv = ActiveSupport::OrderedOptions.new
  @dotenv.ssm = ActiveSupport::OrderedOptions.new
  @dotenv.ssm.autoload = ActiveSupport::OrderedOptions.new
  @dotenv.ssm.autoload.default_skip = ["BASIC_AUTH_USERNAME", "BASIC_AUTH_PASSWORD", "BASIC_AUTH_CREDENTIALS"]
  @dotenv.ssm.autoload.enable = true # autoloads parameters by path IE: /demo/dev/
  @dotenv.ssm.autoload.skip = []
  @dotenv.ssm.convention_resolver = nil # proc receives ssm_leaf_name
  @dotenv.ssm.envs = ActiveSupport::OrderedOptions.new
  @dotenv.ssm.envs.fallback = "dev"
  @dotenv.ssm.envs.unique = ["dev", "prod"]
  @dotenv.ssm.long_env_helper = false   # for completeness
  @dotenv.ssm.long_env_name = false     # helps with Jets 5 legacy

  @base64_encode = true

  # Not yet documented because the config interface may change.
  @git = ActiveSupport::OrderedOptions.new
  @git.push = ActiveSupport::OrderedOptions.new
  @git.push.branch = ActiveSupport::OrderedOptions.new

  @tips = ActiveSupport::OrderedOptions.new
  @tips.enable = true
  @tips.concurrency_change = true
  @tips.env_change = true
  @tips.faster_deploy = true
  @tips.remote_run = true
  @tips.ssm_change = true
end

Instance Attribute Details

#autoload_pathsObject

Returns the value of attribute autoload_paths.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def autoload_paths
  @autoload_paths
end

#base64_encodeObject

Returns the value of attribute base64_encode.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def base64_encode
  @base64_encode
end

#dotenvObject

Returns the value of attribute dotenv.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def dotenv
  @dotenv
end

#gitObject

Returns the value of attribute git.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def git
  @git
end

#ignore_pathsObject

Returns the value of attribute ignore_paths.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def ignore_paths
  @ignore_paths
end

#nameObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jets/core/config/project.rb', line 59

def name
  if ENV["JETS_PROJECT"] && !ENV["JETS_PROJECT"].blank?
    return ENV["JETS_PROJECT"]
  end

  # Too easy to call a method that requires the project name before Jets.boot.
  # Ran into this a few times.
  # IE: Ran into this with Jets API ping. That's no longer requires Jets.project.name
  # But will leave this here in case we miss Jets.boot in the future.
  Jets::Core::Booter.require_config(:project)
  return @name if @name

  project_name = jets_info_project_name
  unless project_name
    puts "ERROR: Jets project name not set".color(:red)
    abort "      Please set config.name in config/jets/project.rb or the JETS_PROJECT environment variable\n      Example:\n\n      config/jets/project.rb\n\n          Jets.project.configure do\n            config.name = \"demo\"\n          end\n\n      Or set the JETS_PROJECT environment variable:\n\n          export JETS_PROJECT=demo\n    EOL\n  end\nend\n"

#tipsObject

Returns the value of attribute tips.



5
6
7
# File 'lib/jets/core/config/project.rb', line 5

def tips
  @tips
end

Instance Method Details

#all_load_pathsObject

Useful for jets rails engine Used to ignore all paths managed by Jets



116
117
118
# File 'lib/jets/core/config/project.rb', line 116

def all_load_paths
  @autoload_paths + @ignore_paths
end

#extension_pathsObject



110
111
112
# File 'lib/jets/core/config/project.rb', line 110

def extension_paths
  @autoload_paths.select { |path| path.ends_with?("/extensions") }
end

#jets_info_project_nameObject



92
93
94
95
# File 'lib/jets/core/config/project.rb', line 92

def jets_info_project_name
  info = Jets::Core::Config::Info.instance
  info.project_name if info.respond_to?(:project_name)
end

#name_inferred?Boolean

Returns:

  • (Boolean)


97
98
99
100
# File 'lib/jets/core/config/project.rb', line 97

def name_inferred?
  name # trigger memoization
  !!@name_inferred
end

#namespaceObject



102
103
104
# File 'lib/jets/core/config/project.rb', line 102

def namespace
  [name, Jets.env, Jets.extra].compact.join("-").tr("_", "-")
end

#s3_bucketObject



106
107
108
# File 'lib/jets/core/config/project.rb', line 106

def s3_bucket
  Jets::Cfn::Resource::S3::JetsBucket.name
end