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:



47
48
49
50
51
# File 'lib/chef-licensing/context.rb', line 47

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_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

#license_keysObject

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



62
63
64
# File 'lib/chef-licensing/context.rb', line 62

def license_keys
  @state.license_keys
end

#transition_to(state) ⇒ Object

The Context allows changing the State object



54
55
56
57
58
59
# File 'lib/chef-licensing/context.rb', line 54

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