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
# 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

  @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



58
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
# File 'lib/jets/core/config/project.rb', line 58

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 <<~EOL
      Please set config.name in config/jets/project.rb or the JETS_PROJECT environment variable
      Example:

      config/jets/project.rb

          Jets.project.configure do
            config.name = "demo"
          end

      Or set the JETS_PROJECT environment variable:

          export JETS_PROJECT=demo
    EOL
  end
end

#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



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

def all_load_paths
  @autoload_paths + @ignore_paths
end

#extension_pathsObject



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

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

#jets_info_project_nameObject



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

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)


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

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

#namespaceObject



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

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

#s3_bucketObject



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

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