Class: Newman::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/newman/settings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

A ‘Newman::Settings` object is a blank slate upon creation. It simply assigns an empty `OpenStruct` object for each type of settings data it supports.

In most situations, you will not instantiate a ‘Newman::Settings` object directly but instead will make use of a configuration file and the `Newman::Settings.from_file` method. Newman provides sample configuration files in its `examples/` and `test/` directories, and applications should do the same. This will help users discover what fields can be set.

We are aware of the fact that the current configuration system is way too flexible and a breeding ground for subtle bugs. This will be fixed in a future version of Newman.



90
91
92
93
94
95
# File 'lib/newman/settings.rb', line 90

def initialize
  self.imap        = OpenStruct.new
  self.smtp        = OpenStruct.new
  self.service     = OpenStruct.new
  self.application = OpenStruct.new
end

Instance Attribute Details

#applicationObject

The ‘imap` and `smtp` fields are used by `Newman::Mailer`, the `service` field is used throughout Newman (particularly in `Newman::Server`), and the `application` field is reserved for application-specific configurations.



104
105
106
# File 'lib/newman/settings.rb', line 104

def application
  @application
end

#imapObject

The ‘imap` and `smtp` fields are used by `Newman::Mailer`, the `service` field is used throughout Newman (particularly in `Newman::Server`), and the `application` field is reserved for application-specific configurations.



104
105
106
# File 'lib/newman/settings.rb', line 104

def imap
  @imap
end

#serviceObject

The ‘imap` and `smtp` fields are used by `Newman::Mailer`, the `service` field is used throughout Newman (particularly in `Newman::Server`), and the `application` field is reserved for application-specific configurations.



104
105
106
# File 'lib/newman/settings.rb', line 104

def service
  @service
end

#smtpObject

The ‘imap` and `smtp` fields are used by `Newman::Mailer`, the `service` field is used throughout Newman (particularly in `Newman::Server`), and the `application` field is reserved for application-specific configurations.



104
105
106
# File 'lib/newman/settings.rb', line 104

def smtp
  @smtp
end

Class Method Details

.from_file(filename) ⇒ Object

The ‘Newman::Settings.from_file` method is used to create a new `Newman::Settings` object and populate it with the data contained in a settings file, i.e.

settings = Newman::Settings.from_file('config/environment.rb')

This method is purely syntactic sugar, and is functionally equivalent to the following code:

settings = Newman::Settings.new
settings.load_config('config/environment.rb')

Because there currently is little advantage to explicitly instantiating a blank ‘Newman::Settings` object, this method is the preferred way of doing things.



70
71
72
# File 'lib/newman/settings.rb', line 70

def self.from_file(filename)
  new.tap { |o| o.load_config(filename) }
end

Instance Method Details

#load_config(filename) ⇒ Object

‘Newman::Settings#load_config` is used for evaluating the contents of a file within the context of a `Newman::Settings` instance.

In practice, this method is typically called by ‘Newman::Settings#from_file`, but can also be used to apply multiple settings files to a single `Newman::Settings` object



117
118
119
# File 'lib/newman/settings.rb', line 117

def load_config(filename)
  eval(File.read(filename), binding)
end