Class: Opener::Daemons::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/daemons/configuration.rb

Overview

Configuration object for storing details about a single job.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, component_options = {}, options = {}) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • component (Class)

    The component to use.

  • component_options (Hash) (defaults to: {})

    Options to pass to the component.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :input_url (String)
  • :identifier (String)
  • :callbacks (Array)
  • :metadata (Hash)


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/opener/daemons/configuration.rb', line 39

def initialize(component, component_options = {}, options = {})
  @component         = component
  @component_options = component_options

  options.each do |key, value|
    instance_variable_set("@#{key}", value) if respond_to?(key)
  end

  @callbacks ||= []
  @metadata  ||= {}
end

Instance Attribute Details

#callbacksArray (readonly)

Returns:

  • (Array)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opener/daemons/configuration.rb', line 21

class Configuration

  attr_reader :component, :component_options

  attr_reader :input, :input_url
  attr_reader :callbacks, :metadata

  ##
  # @param [Class] component The component to use.
  # @param [Hash] component_options Options to pass to the component.
  #
  # @param [Hash] options
  #
  # @option options [String] :input_url
  # @option options [String] :identifier
  # @option options [Array] :callbacks
  # @option options [Hash] :metadata
  #
  def initialize(component, component_options = {}, options = {})
    @component         = component
    @component_options = component_options

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end

    @callbacks ||= []
    @metadata  ||= {}
  end

  ##
  # Returns the identifier of the document. If no identifier was given a
  # unique one will be generated instead.
  #
  # @return [String]
  #
  def identifier
    return @identifier ||= SecureRandom.hex
  end

  ##
  # Returns a new instance of the component.
  #
  # @return [Object]
  #
  def component_instance
    return component.new(component_options)
  end

end

#componentClass (readonly)

Returns:

  • (Class)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opener/daemons/configuration.rb', line 21

class Configuration

  attr_reader :component, :component_options

  attr_reader :input, :input_url
  attr_reader :callbacks, :metadata

  ##
  # @param [Class] component The component to use.
  # @param [Hash] component_options Options to pass to the component.
  #
  # @param [Hash] options
  #
  # @option options [String] :input_url
  # @option options [String] :identifier
  # @option options [Array] :callbacks
  # @option options [Hash] :metadata
  #
  def initialize(component, component_options = {}, options = {})
    @component         = component
    @component_options = component_options

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end

    @callbacks ||= []
    @metadata  ||= {}
  end

  ##
  # Returns the identifier of the document. If no identifier was given a
  # unique one will be generated instead.
  #
  # @return [String]
  #
  def identifier
    return @identifier ||= SecureRandom.hex
  end

  ##
  # Returns a new instance of the component.
  #
  # @return [Object]
  #
  def component_instance
    return component.new(component_options)
  end

end

#component_optionsHash (readonly)

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opener/daemons/configuration.rb', line 21

class Configuration

  attr_reader :component, :component_options

  attr_reader :input, :input_url
  attr_reader :callbacks, :metadata

  ##
  # @param [Class] component The component to use.
  # @param [Hash] component_options Options to pass to the component.
  #
  # @param [Hash] options
  #
  # @option options [String] :input_url
  # @option options [String] :identifier
  # @option options [Array] :callbacks
  # @option options [Hash] :metadata
  #
  def initialize(component, component_options = {}, options = {})
    @component         = component
    @component_options = component_options

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end

    @callbacks ||= []
    @metadata  ||= {}
  end

  ##
  # Returns the identifier of the document. If no identifier was given a
  # unique one will be generated instead.
  #
  # @return [String]
  #
  def identifier
    return @identifier ||= SecureRandom.hex
  end

  ##
  # Returns a new instance of the component.
  #
  # @return [Object]
  #
  def component_instance
    return component.new(component_options)
  end

end

#inputObject (readonly)

Returns the value of attribute input.



25
26
27
# File 'lib/opener/daemons/configuration.rb', line 25

def input
  @input
end

#input_urlString (readonly)

Returns:

  • (String)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opener/daemons/configuration.rb', line 21

class Configuration

  attr_reader :component, :component_options

  attr_reader :input, :input_url
  attr_reader :callbacks, :metadata

  ##
  # @param [Class] component The component to use.
  # @param [Hash] component_options Options to pass to the component.
  #
  # @param [Hash] options
  #
  # @option options [String] :input_url
  # @option options [String] :identifier
  # @option options [Array] :callbacks
  # @option options [Hash] :metadata
  #
  def initialize(component, component_options = {}, options = {})
    @component         = component
    @component_options = component_options

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end

    @callbacks ||= []
    @metadata  ||= {}
  end

  ##
  # Returns the identifier of the document. If no identifier was given a
  # unique one will be generated instead.
  #
  # @return [String]
  #
  def identifier
    return @identifier ||= SecureRandom.hex
  end

  ##
  # Returns a new instance of the component.
  #
  # @return [Object]
  #
  def component_instance
    return component.new(component_options)
  end

end

#metadataHash (readonly)

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opener/daemons/configuration.rb', line 21

class Configuration

  attr_reader :component, :component_options

  attr_reader :input, :input_url
  attr_reader :callbacks, :metadata

  ##
  # @param [Class] component The component to use.
  # @param [Hash] component_options Options to pass to the component.
  #
  # @param [Hash] options
  #
  # @option options [String] :input_url
  # @option options [String] :identifier
  # @option options [Array] :callbacks
  # @option options [Hash] :metadata
  #
  def initialize(component, component_options = {}, options = {})
    @component         = component
    @component_options = component_options

    options.each do |key, value|
      instance_variable_set("@#{key}", value) if respond_to?(key)
    end

    @callbacks ||= []
    @metadata  ||= {}
  end

  ##
  # Returns the identifier of the document. If no identifier was given a
  # unique one will be generated instead.
  #
  # @return [String]
  #
  def identifier
    return @identifier ||= SecureRandom.hex
  end

  ##
  # Returns a new instance of the component.
  #
  # @return [Object]
  #
  def component_instance
    return component.new(component_options)
  end

end

Instance Method Details

#component_instanceObject

Returns a new instance of the component.

Returns:

  • (Object)


66
67
68
# File 'lib/opener/daemons/configuration.rb', line 66

def component_instance
  return component.new(component_options)
end

#identifierString

Returns the identifier of the document. If no identifier was given a unique one will be generated instead.

Returns:

  • (String)


57
58
59
# File 'lib/opener/daemons/configuration.rb', line 57

def identifier
  return @identifier ||= SecureRandom.hex
end