Class: Itly::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/itly/options.rb,
lib/itly/options/validation.rb,
lib/itly/options/environment.rb

Overview

Options class for Itly object initialization

Defined Under Namespace

Modules: Environment, Validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment: Itly::Options::Environment::DEVELOPMENT, disabled: false, plugins: [], validation: nil, logger: nil, on_validation_error: nil) ⇒ Options

Create a new Options object with default values



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/itly/options.rb', line 59

def initialize(
  environment: Itly::Options::Environment::DEVELOPMENT,
  disabled: false,
  plugins: [],
  validation: nil,
  logger: nil,
  on_validation_error: nil
)
  @environment = environment
  @disabled = disabled
  @plugins = plugins
  @validation = validation
  @logger = logger
  @on_validation_error = on_validation_error
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



53
54
55
# File 'lib/itly/options.rb', line 53

def disabled
  @disabled
end

#environmentObject

Returns the value of attribute environment.



53
54
55
# File 'lib/itly/options.rb', line 53

def environment
  @environment
end

#loggerObject

Returns the value of attribute logger.



53
54
55
# File 'lib/itly/options.rb', line 53

def logger
  @logger
end

#on_validation_errorObject

Returns the value of attribute on_validation_error.



53
54
55
# File 'lib/itly/options.rb', line 53

def on_validation_error
  @on_validation_error
end

#pluginsObject

Returns the value of attribute plugins.



53
54
55
# File 'lib/itly/options.rb', line 53

def plugins
  @plugins
end

#validationItly::Options::Validation

Return the current validation behavior

Returns:



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/itly/options.rb', line 89

def validation
  if @validation.nil?
    if development?
      Itly::Options::Validation::ERROR_ON_INVALID
    else
      Itly::Options::Validation::TRACK_INVALID
    end
  else
    @validation
  end
end

Instance Method Details

#development?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/itly/options/environment.rb', line 16

def development?
  @environment == Itly::Options::Environment::DEVELOPMENT
end

#for_pluginItly::PluginOptions

Returns the options that are passed to plugin #load

Returns:



80
81
82
# File 'lib/itly/options.rb', line 80

def for_plugin
  ::Itly::PluginOptions.new environment: environment, logger: logger
end

#production?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/itly/options/environment.rb', line 20

def production?
  @environment == Itly::Options::Environment::PRODUCTION
end