Class: Upfluence::Peer

Inherits:
Object
  • Object
show all
Defined in:
lib/upfluence/peer.rb

Defined Under Namespace

Classes: Version

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authority:, instance_name:, app_name:, project_name:, environment:, version: nil) ⇒ Peer

Returns a new instance of Peer.



77
78
79
80
81
82
83
84
85
# File 'lib/upfluence/peer.rb', line 77

def initialize(authority:, instance_name:, app_name:, project_name:,
               environment:, version: nil)
  @authority = authority || 'local'
  @instance_name = instance_name ||  'unknown-server'
  @app_name = app_name || 'unknown-app'
  @project_name = project_name || 'unknown-app'
  @environment = environment || 'development'
  @version = version
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



74
75
76
# File 'lib/upfluence/peer.rb', line 74

def app_name
  @app_name
end

#authorityObject (readonly)

Returns the value of attribute authority.



74
75
76
# File 'lib/upfluence/peer.rb', line 74

def authority
  @authority
end

#environmentObject (readonly)

Returns the value of attribute environment.



74
75
76
# File 'lib/upfluence/peer.rb', line 74

def environment
  @environment
end

#instance_nameObject (readonly)

Returns the value of attribute instance_name.



74
75
76
# File 'lib/upfluence/peer.rb', line 74

def instance_name
  @instance_name
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



74
75
76
# File 'lib/upfluence/peer.rb', line 74

def project_name
  @project_name
end

Class Method Details

.from_envObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/upfluence/peer.rb', line 99

def from_env
  Peer.new(
    authority:     ENV['AUTHORITY'],
    instance_name: ENV['UNIT_NAME'],
    app_name:      ENV['APP_NAME'],
    project_name:  ENV['PROJECT_NAME'],
    environment:   ENV['ENV'],
    version:       Version.new(
      build_git_version,
      Version::SemanticVersion.parse(ENV['VERSION'])
    )
  )
end

Instance Method Details

#to_urlObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/upfluence/peer.rb', line 87

def to_url
  query = {
    'app-name'         => @app_name,
    'project-name'     => @project_name,
    'git-version'      => @version.git&.commit,
    'semantic-version' => @version.semantic&.to_s
  }.compact.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join('&')

  "peer://#{@environment}@#{@authority}/#{@instance_name}?#{query}"
end