Class: Flagsmith::Engine::Environments::ApiKey

Inherits:
Object
  • Object
show all
Defined in:
lib/flagsmith/engine/environments/models.rb

Overview

EnvironmentApiKeyModel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ApiKey

Returns a new instance of ApiKey.



36
37
38
39
40
41
42
43
44
# File 'lib/flagsmith/engine/environments/models.rb', line 36

def initialize(params = {})
  @id = params.fetch(:id)
  @key = params.fetch(:key)
  @name = params.fetch(:name)
  @client_api_key = params.fetch(:client_api_key)
  @created_at = params.fetch(:created_at, Time.now)
  @expires_at = params.fetch(:expires_at, nil)
  @active = params.fetch(:active, true)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



34
35
36
# File 'lib/flagsmith/engine/environments/models.rb', line 34

def active
  @active
end

#client_api_keyObject (readonly)

Returns the value of attribute client_api_key.



33
34
35
# File 'lib/flagsmith/engine/environments/models.rb', line 33

def client_api_key
  @client_api_key
end

#created_atObject (readonly)

Returns the value of attribute created_at.



33
34
35
# File 'lib/flagsmith/engine/environments/models.rb', line 33

def created_at
  @created_at
end

#expires_atObject

Returns the value of attribute expires_at.



34
35
36
# File 'lib/flagsmith/engine/environments/models.rb', line 34

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



33
34
35
# File 'lib/flagsmith/engine/environments/models.rb', line 33

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



33
34
35
# File 'lib/flagsmith/engine/environments/models.rb', line 33

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/flagsmith/engine/environments/models.rb', line 33

def name
  @name
end

Class Method Details

.build(json) ⇒ Object



51
52
53
54
55
56
# File 'lib/flagsmith/engine/environments/models.rb', line 51

def build(json)
  attributes = json.slice(:id, :key, :name, :client_api_key, :active)
  attributes = attributes.merge(expires_at: Date.parse(json[:created_at])) unless json[:created_at].nil?
  attributes = attributes.merge(expires_at: Date.parse(json[:expires_at])) unless json[:expires_at].nil?
  new(**attributes)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/flagsmith/engine/environments/models.rb', line 46

def valid?
  active && (!expires_at || expires_at > Time.now)
end