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.



47
48
49
50
51
52
53
54
55
# File 'lib/flagsmith/engine/environments/models.rb', line 47

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.



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

def active
  @active
end

#client_api_keyObject (readonly)

Returns the value of attribute client_api_key.



44
45
46
# File 'lib/flagsmith/engine/environments/models.rb', line 44

def client_api_key
  @client_api_key
end

#created_atObject (readonly)

Returns the value of attribute created_at.



44
45
46
# File 'lib/flagsmith/engine/environments/models.rb', line 44

def created_at
  @created_at
end

#expires_atObject

Returns the value of attribute expires_at.



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

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



44
45
46
# File 'lib/flagsmith/engine/environments/models.rb', line 44

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



44
45
46
# File 'lib/flagsmith/engine/environments/models.rb', line 44

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



44
45
46
# File 'lib/flagsmith/engine/environments/models.rb', line 44

def name
  @name
end

Class Method Details

.build(json) ⇒ Object



62
63
64
65
66
67
# File 'lib/flagsmith/engine/environments/models.rb', line 62

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)


57
58
59
# File 'lib/flagsmith/engine/environments/models.rb', line 57

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