Class: ChefLicensing::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/context.rb

Defined Under Namespace

Classes: Global, Local, State

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, options = {}) ⇒ Context

Returns a new instance of Context.

Parameters:



58
59
60
61
62
# File 'lib/chef-licensing/context.rb', line 58

def initialize(state, options = {})
  @options = options
  @logger = ChefLicensing::Config.logger
  transition_to(state)
end

Class Attribute Details

.current_context=(value) ⇒ Object

Sets the attribute current_context

Parameters:

  • value

    the value to set the attribute current_context to.



14
15
16
# File 'lib/chef-licensing/context.rb', line 14

def current_context=(value)
  @current_context = value
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/chef-licensing/context.rb', line 11

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/chef-licensing/context.rb', line 11

def options
  @options
end

#stateObject

Returns the value of attribute state.



10
11
12
# File 'lib/chef-licensing/context.rb', line 10

def state
  @state
end

Class Method Details

.license(options = {}) ⇒ Object

Return license context object via current context



29
30
31
# File 'lib/chef-licensing/context.rb', line 29

def license(options = {})
  current_context(options).license
end

.license=(license) ⇒ Object

Set license context object via current context Example: ChefLicensing::Context.license = license_context_object



35
36
37
# File 'lib/chef-licensing/context.rb', line 35

def license=(license)
  current_context.license = license
end

.license_keys(options = {}) ⇒ Object

Return license keys from current context



24
25
26
# File 'lib/chef-licensing/context.rb', line 24

def license_keys(options = {})
  current_context(options).license_keys
end

.local_licensing_service?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/chef-licensing/context.rb', line 16

def local_licensing_service?
  ChefLicensing::Config.is_local_license_service ||= LicensingService::Local.detected?
end

Instance Method Details

#licenseObject

Get license context from local or global state



78
79
80
# File 'lib/chef-licensing/context.rb', line 78

def license
  @state.license
end

#license=(license) ⇒ Object

Set license context from local or global state



83
84
85
# File 'lib/chef-licensing/context.rb', line 83

def license=(license)
  @state.license = license
end

#license_keysObject

The Context delegates part of its behavior to the current State object.



73
74
75
# File 'lib/chef-licensing/context.rb', line 73

def license_keys
  @state.license_keys
end

#transition_to(state) ⇒ Object

The Context allows changing the State object



65
66
67
68
69
70
# File 'lib/chef-licensing/context.rb', line 65

def transition_to(state)
  logger.debug "Chef Licensing Context: Transition to #{state.class}"
  @state = state
  @state.context = self
  @state.options = options
end