Module: Reactive

Defined in:
lib/reactive-core/errors.rb,
lib/reactive-core/request.rb,
lib/reactive-core/version.rb,
lib/reactive-core/response.rb,
lib/reactive-core/dispatcher.rb,
lib/reactive-core/meta_model.rb,
lib/reactive-core/initializer.rb,
lib/reactive-core/updater/cli.rb,
lib/reactive-core/updater/gui.rb,
lib/reactive-core/updater/base.rb,
lib/reactive-core/gem_dependency.rb,
lib/reactive-core/output_handler.rb

Defined Under Namespace

Modules: Dispatcher, MetaModel, OutputHandler, TemplateError, Updater, VERSION Classes: Configuration, Error, GemDependency, Initializer, Request, Response

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configuration ⇒ Object

The reactive configuration used for the application.



10
11
12
# File 'lib/reactive-core/initializer.rb', line 10

def configuration
  @configuration
end

.logger ⇒ Object

The logger instance used by the framework. Plugins may copy this reference, thus changing it lately (after init time) may not have the desired effect.



14
15
16
# File 'lib/reactive-core/initializer.rb', line 14

def logger
  @logger
end

Class Method Details

.dir_for(type) ⇒ Object

Returns the directory for the type passed. Returns nil if no directory is configured for the passed type.

Examples:

dir_for(:config)  => "/home/lambda/mysales/config"
dir_for(:views)  => "/home/lambda/mysales/app/views"


27
28
29
# File 'lib/reactive-core/initializer.rb', line 27

def dir_for(type)
  dirs_for(type).first
end

.dirs_for(type) ⇒ Object

Returns an array of directories for the type passed. Returns an empty array if no directory is configured for the passed type.

Examples:

dirs_for(:config)  => ["/home/lambda/mysales/config"]
dirs_for(:views)  => ["/home/lambda/mysales/app/views", "/home/lambda/mysales/app/special_views"]


37
38
39
# File 'lib/reactive-core/initializer.rb', line 37

def dirs_for(type)
  [configuration.paths[type]].flatten.compact
end

.file_for(*parts) ⇒ Object

Returns the complete pathname for a given file (the last argument) in a given path (other parts) specified with a similar form than #path_for. You may also pass wildcards as defined in Dir#glob, when this is the case, the first matching file is returned.



57
58
59
# File 'lib/reactive-core/initializer.rb', line 57

def file_for(*parts)
  files_for(*parts).first
end

.file_for!(*parts) ⇒ Object

Returns the complete pathname for a given file (the last argument) in a given path (other parts) specified with a similar form than #path_for. Raises an Errno::ENOENT exception if none matched.



75
76
77
# File 'lib/reactive-core/initializer.rb', line 75

def file_for!(*parts)
  file_for(*parts) or raise Errno::ENOENT
end

.files_for(*parts) ⇒ Object

Returns the complete pathnames for a given glob path relative to the application root, see #path_for for more information.

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
71
# File 'lib/reactive-core/initializer.rb', line 62

def files_for(*parts)
  root_dirs = parts.first.is_a?(Symbol) ? dirs_for(path_type = parts.shift) : [configuration.root_dir]
  raise ArgumentError, defined?(path_type) ? "No defined path for #{path_type}" : "No root dir defined!" if root_dirs.empty?
  root_dirs.each do |dir|
    pathname = File.join(dir, *parts)
    filenames = Dir.glob(pathname).select {|item| File.file? item}
    return filenames unless filenames.empty?
  end
  []
end

.path_for(*parts) ⇒ Object

Constructs an absolute path with parts relative to the application root or relative to a typed directory.

Raises an ArgumentError if no directory is configured for the passed type.

Examples:

path_for("log", "production.log") # => "/home/lambda/mysales/log/production.log"
path_for(:views, "main", "run.rb") # => /home/lambda/mysales/app/views/main/run.rb"

Raises:

  • (ArgumentError)


49
50
51
52
53
# File 'lib/reactive-core/initializer.rb', line 49

def path_for(*parts)
  root_dir = parts.first.is_a?(Symbol) ? dir_for(path_type = parts.shift) : configuration.root_dir
  raise ArgumentError, defined?(path_type) ? "No defined path for #{path_type}" : "No root dir defined!" unless root_dir
  File.join(root_dir, *parts)
end

.relative_path_for(*parts) ⇒ Object

Constructs a relative path (to the application root) with parts relative to the application root or relative to a typed directory.

Examples:

relative_path_for("log", "production.log") # => "log/production.log"
relative_path_for(:views, "main", "run.rb") # => "app/views/main/run.rb"


85
86
87
# File 'lib/reactive-core/initializer.rb', line 85

def relative_path_for(*parts)
  path_for(*parts).sub("#{configuration.root_dir}/", '')
end

.version ⇒ Object

Returns the Reactive version as a String



17
18
19
# File 'lib/reactive-core/initializer.rb', line 17

def version
  VERSION::STRING
end