Class: Cosmos::EnvironmentModel

Inherits:
Model show all
Defined in:
lib/cosmos/models/environment_model.rb

Constant Summary collapse

PRIMARY_KEY =
'__cosmos__environment'.freeze

Instance Attribute Summary

Attributes inherited from Model

#name, #plugin, #scope, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#as_config, #create, #deploy, #destroy, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, names, set, #undeploy, #update

Constructor Details

#initialize(name:, scope:, key:, value:) ⇒ EnvironmentModel

Returns a new instance of EnvironmentModel.



43
44
45
46
47
# File 'lib/cosmos/models/environment_model.rb', line 43

def initialize(name:, scope:, key:, value:)
  super("#{scope}#{PRIMARY_KEY}", name: name, scope: scope)
  @key = key
  @value = value
end

Class Method Details

.all(scope:) ⇒ Object



35
36
37
# File 'lib/cosmos/models/environment_model.rb', line 35

def self.all(scope:)
  super("#{scope}#{PRIMARY_KEY}")
end

.destroy(scope:, name:) ⇒ Object



39
40
41
# File 'lib/cosmos/models/environment_model.rb', line 39

def self.destroy(scope:, name:)
  Store.hdel("#{scope}#{PRIMARY_KEY}", name)
end

.get(name:, scope:) ⇒ Object

NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work



31
32
33
# File 'lib/cosmos/models/environment_model.rb', line 31

def self.get(name:, scope:)
  super("#{scope}#{PRIMARY_KEY}", name: name)
end

Instance Method Details

#as_jsonObject



49
50
51
52
53
54
55
56
# File 'lib/cosmos/models/environment_model.rb', line 49

def as_json
  {
    'name' => @name,
    'updated_at' => @updated_at,
    'key' => @key,
    'value' => @value
  }
end