Module: Arborist

Extended by:
MethodUtilities, Configurability, Loggability
Defined in:
lib/arborist.rb,
lib/arborist/mixins.rb,
lib/arborist/exceptions.rb

Overview

Arborist namespace

Defined Under Namespace

Modules: CLI, EventAPI, HashUtilities, MethodUtilities, NetworkUtilities, TimeFunctions, TimeRefinements, TreeAPI Classes: Client, ClientError, ConfigError, Dependency, Event, Loader, Manager, MessageError, Monitor, MonitorRunner, Node, NodeError, NodeSubscription, Observer, ObserverRunner, ServerError, Subscription

Constant Summary collapse

VERSION =

Package version

'0.6.0'
REVISION =

Version control revision

%q$Revision$
CONFIG_ENV =

The name of the environment variable which can be used to set the config path

'ARBORIST_CONFIG'
LOCAL_CONFIG_FILE =

The name of the config file for local overrides.

Pathname( '~/.arborist.yml' ).expand_path
DEFAULT_CONFIG_FILE =

The name of the config file that’s loaded if none is specified.

Pathname( 'arborist.yml' ).expand_path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, dsl_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Class Method Details

.add_dsl_constructor(subclass, &method_body) ⇒ Object

Add a constructor function to the Arborist namespace called name with the specified method_body.



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/arborist.rb', line 90

def self::add_dsl_constructor( subclass, &method_body )
  name = subclass.name.dup

  if name
    name.sub!( /.*::/, '' )
    self.log.debug "Adding factory method for %p: %p" % [ name, method_body ]
    singleton_class.instance_exec( name, method_body ) do |name, body|
      define_method( name, &body )
    end
  else
    self.log.info "Skipping DSL constructor for anonymous class."
  end
end

.clientObject

Return a new Arborist::Client.



141
142
143
# File 'lib/arborist.rb', line 141

def self::client
  return Arborist::Client.new
end

.configObject

Get the loaded config (a Configurability::Config object)



60
61
62
# File 'lib/arborist.rb', line 60

def self::config
  Configurability.loaded_config
end

.config_loaded?Boolean

Returns true if the configuration has been loaded at least once.

Returns:

  • (Boolean)


66
67
68
# File 'lib/arborist.rb', line 66

def self::config_loaded?
  return self.config ? true : false
end

.load_allObject

Load all node and event types



147
148
149
# File 'lib/arborist.rb', line 147

def self::load_all
  Arborist::Node.load_all
end

.load_config(config_file = nil, defaults = nil) ⇒ Object

Load the specified config_file, install the config in all objects with Configurability, and call any callbacks registered via #after_configure.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/arborist.rb', line 73

def self::load_config( config_file=nil, defaults=nil )
  config_file ||= ENV[ CONFIG_ENV ]
  config_file ||= LOCAL_CONFIG_FILE if LOCAL_CONFIG_FILE.exist?
  config_file ||= DEFAULT_CONFIG_FILE

  defaults    ||= Configurability.gather_defaults

  self.log.info "Loading config from %p with defaults for sections: %p." %
    [ config_file, defaults.keys ]
  config = Configurability::Config.load( config_file, defaults )

  config.install
end

.manager_for(loader) ⇒ Object

Return a new Arborist::Manager for the nodes loaded by the specified loader.



106
107
108
109
110
111
112
113
# File 'lib/arborist.rb', line 106

def self::manager_for( loader )
  self.load_all
  nodes = Arborist::Node.each_in( loader )
  manager = Arborist::Manager.new
  manager.load_tree( nodes )

  return manager
end

.monitor_runner_for(loader) ⇒ Object

Return a new Arborist::MonitorRunner for the monitors described in files under the specified loader.



118
119
120
121
122
123
124
125
# File 'lib/arborist.rb', line 118

def self::monitor_runner_for( loader )
  self.load_all
  monitors = Arborist::Monitor.each_in( loader )
  runner = Arborist::MonitorRunner.new
  runner.load_monitors( monitors )

  return runner
end

.observer_runner_for(loader) ⇒ Object

Return a new Arborist::ObserverRunner for the observers described in files under the specified loader.



130
131
132
133
134
135
136
137
# File 'lib/arborist.rb', line 130

def self::observer_runner_for( loader )
  self.load_all
  observers = Arborist::Observer.each_in( loader )
  runner = Arborist::ObserverRunner.new
  runner.load_observers( observers )

  return runner
end

Instance Method Details

#arboristObject

Set up a logger for the Arborist namespace



35
# File 'lib/arborist.rb', line 35

log_as :arborist