Class: Flagsmith::Engine::Environments::ApiKey
- Inherits:
-
Object
- Object
- Flagsmith::Engine::Environments::ApiKey
- Defined in:
- lib/flagsmith/engine/environments/models.rb
Overview
EnvironmentApiKeyModel
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#client_api_key ⇒ Object
readonly
Returns the value of attribute client_api_key.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ ApiKey
constructor
A new instance of ApiKey.
- #valid? ⇒ Boolean
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
#active ⇒ Object
Returns the value of attribute active.
34 35 36 |
# File 'lib/flagsmith/engine/environments/models.rb', line 34 def active @active end |
#client_api_key ⇒ Object (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_at ⇒ Object (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_at ⇒ Object
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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
33 34 35 |
# File 'lib/flagsmith/engine/environments/models.rb', line 33 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
33 34 35 |
# File 'lib/flagsmith/engine/environments/models.rb', line 33 def key @key end |
#name ⇒ Object (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
46 47 48 |
# File 'lib/flagsmith/engine/environments/models.rb', line 46 def valid? active && (!expires_at || expires_at > Time.now) end |