Class: Skylight::Util::Component Private

Inherits:
Object
  • Object
show all
Defined in:
lib/skylight/util/component.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

NAME_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/\A[a-zA-Z0-9_-]+\z/.freeze
DEFAULT_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"web"
WORKER_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"worker"
DEFAULT_ENVIRONMENT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"production"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, name, force_worker: false) ⇒ Component

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Component.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
# File 'lib/skylight/util/component.rb', line 15

def initialize(environment, name, force_worker: false)
  @environment = environment || DEFAULT_ENVIRONMENT
  @name = resolve_name(name, force_worker)

  raise ArgumentError, "environment can't be blank" if @environment.empty?

  validate_string!(@environment, "environment")
  validate_string!(@name, "name")
end

Instance Attribute Details

#environmentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/skylight/util/component.rb', line 8

def environment
  @environment
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/skylight/util/component.rb', line 8

def name
  @name
end

Instance Method Details

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

keys here should match those from the main config



42
43
44
# File 'lib/skylight/util/component.rb', line 42

def as_json(*)
  { component: name, env: environment }
end

#to_encoded_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/skylight/util/component.rb', line 29

def to_encoded_s
  @to_encoded_s ||= URI.encode_www_form_component(to_s)
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/skylight/util/component.rb', line 25

def to_s
  "#{name}:#{environment}"
end

#web?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


33
34
35
# File 'lib/skylight/util/component.rb', line 33

def web?
  name == DEFAULT_NAME
end

#worker?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


37
38
39
# File 'lib/skylight/util/component.rb', line 37

def worker?
  !web?
end