Class: Siding::ProjectKey
- Inherits:
-
Object
- Object
- Siding::ProjectKey
- Defined in:
- lib/siding/project_key.rb
Constant Summary collapse
- DIGEST_LENGTH =
Long enough that a collision is not a practical concern, short enough that the socket path built from it stays inside the platform's ~100-byte sockaddr_un limit.
12
Instance Attribute Summary collapse
-
#app_env ⇒ Object
readonly
Returns the value of attribute app_env.
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#tool_version ⇒ Object
readonly
Returns the value of attribute tool_version.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #digest ⇒ Object
- #fields ⇒ Object
- #hash ⇒ Object
-
#initialize(app_root:, uid:, tool_version:, ruby_version:, app_env:) ⇒ ProjectKey
constructor
A new instance of ProjectKey.
- #inspect ⇒ Object
- #label ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(app_root:, uid:, tool_version:, ruby_version:, app_env:) ⇒ ProjectKey
Returns a new instance of ProjectKey.
29 30 31 32 33 34 35 |
# File 'lib/siding/project_key.rb', line 29 def initialize(app_root:, uid:, tool_version:, ruby_version:, app_env:) @app_root = File.realpath(app_root) @uid = uid @tool_version = tool_version @ruby_version = ruby_version @app_env = app_env end |
Instance Attribute Details
#app_env ⇒ Object (readonly)
Returns the value of attribute app_env.
12 13 14 |
# File 'lib/siding/project_key.rb', line 12 def app_env @app_env end |
#app_root ⇒ Object (readonly)
Returns the value of attribute app_root.
12 13 14 |
# File 'lib/siding/project_key.rb', line 12 def app_root @app_root end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
12 13 14 |
# File 'lib/siding/project_key.rb', line 12 def ruby_version @ruby_version end |
#tool_version ⇒ Object (readonly)
Returns the value of attribute tool_version.
12 13 14 |
# File 'lib/siding/project_key.rb', line 12 def tool_version @tool_version end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
12 13 14 |
# File 'lib/siding/project_key.rb', line 12 def uid @uid end |
Class Method Details
.app_env_from(env) ⇒ Object
24 25 26 27 |
# File 'lib/siding/project_key.rb', line 24 def self.app_env_from(env) value = env["RAILS_ENV"] || env["RACK_ENV"] value.nil? || value.empty? ? "development" : value end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
49 50 51 |
# File 'lib/siding/project_key.rb', line 49 def ==(other) other.is_a?(ProjectKey) && fields == other.fields end |
#digest ⇒ Object
37 38 39 |
# File 'lib/siding/project_key.rb', line 37 def digest @digest ||= Digest::SHA256.hexdigest(fields.join("\0"))[0, DIGEST_LENGTH] end |
#fields ⇒ Object
45 46 47 |
# File 'lib/siding/project_key.rb', line 45 def fields [app_root, uid.to_s, tool_version, ruby_version, app_env] end |
#hash ⇒ Object
54 55 56 |
# File 'lib/siding/project_key.rb', line 54 def hash fields.hash end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/siding/project_key.rb', line 60 def inspect "#<#{self.class} #{label} root=#{app_root} uid=#{uid} tool=#{tool_version} ruby=#{ruby_version}>" end |
#label ⇒ Object
41 42 43 |
# File 'lib/siding/project_key.rb', line 41 def label "#{File.basename(app_root)}-#{app_env}-#{digest}" end |
#to_s ⇒ Object
58 |
# File 'lib/siding/project_key.rb', line 58 def to_s = label |