Class: Scribbler::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/scribbler/configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#application_includeObject

Boolean used for deciding whether or not Scribbler should define #*_log_location methods and a .log method in a rails application

Default: false

Examples

Scribbler::Configurator.application_include # => false

Returns boolean

TODO: Allow the class we’re sending the include to to be custom



87
88
89
# File 'lib/scribbler/configurator.rb', line 87

def application_include
  @application_include
end

#log_directoryObject

Provides location for getting the directory Scribbler will place log files in. Favors RailsApplication/log/ but falls back to $PWD/log if not set in config

Examples

Configurator.log_directory
# => "/some/path/to/log/"

Returns String for log directory location



65
66
67
# File 'lib/scribbler/configurator.rb', line 65

def log_directory
  @log_directory
end

#logsObject

Returns the value of attribute logs.



3
4
5
# File 'lib/scribbler/configurator.rb', line 3

def logs
  @logs
end

#templateObject

The method that sets a template for each log made with Scribbler.log

The template proc is given the whole options hash that is passed through Scribbler.log or YourApplication.log. So if you had:

YourApplication.log :a_log,
                    :message => "information data",
                    :custom => "stuff"

Then you can assume the template proc will get:

options =

:message => "information data",
:custom => "stuff"

To set a custom template:

Scribbler::Configurator.template = proc do |options|
  "Message: options[:message]"
end

From Scribbler.configure that would be:

config.template = proc do |options|
  "Message: options[:message]"
end

**Keep in mind** that the template can be ignored at any Scribbler.log call with:

Scribbler.log :your_log, :template => false, :message "..."

Default:


SomeObject: #id # options and options.try(:id) Custom1: some good info # options hash Custom2: some better info # Left of colon is the key.humanize, right is the value OH NO YOU BROKED STUFF # options.strip_heredoc DO PLX FIX #

Examples

Scribbler::Configurator.template
# => <#Proc:...>

Returns the proc that wraps around each log entry

TODO: Block input that would break this TODO: Test



159
160
161
# File 'lib/scribbler/configurator.rb', line 159

def template
  @template
end

#use_template_by_defaultObject

Boolean for deciding if we should use the logger template by by default when calling Scribbler.log

Default: false

Examples

Scribbler::Configurator.use_template_by_default # => false

Returns boolean



102
103
104
# File 'lib/scribbler/configurator.rb', line 102

def use_template_by_default
  @use_template_by_default
end

Instance Method Details

#default_install_pathObject

Gets the path to the default install directory. If Rails is present it will default to the Rails.root/config/initializers/. Otherwise it assumes its the $PWD/config/initializer. Should look at a cleaner abstraction of this

Examples:

Configurator.default_install_path
# => '/some/home/projects/rails_app/config/initializers/'

Returns String for best guess of a good install path



47
48
49
50
51
52
53
# File 'lib/scribbler/configurator.rb', line 47

def default_install_path
  begin
    ::Rails.root.join 'config', 'initializers', ''
  rescue NameError
    File.join Dir.pwd, 'config', 'initializers', ''
  end
end

#gem_pathObject

Gets the path of this Gem

Examples:

Configurator.gem_path
# => '/some/home/.rvm/gems/ruby-1.9.3-p125/gems/scribbler-0.0.1/'

Returns String of the current gem’s directory path



19
20
21
# File 'lib/scribbler/configurator.rb', line 19

def gem_path
  File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
end

#templatesObject

Gets all the paths to the template files in the gem’s template directory

Examples:

Configurator.templates
# => ['/some/home/.rvm/gems/ruby-1.9.3-p125/gems/scribbler-0.0.1/templates/1.rb',
#     '/some/home/.rvm/gems/ruby-1.9.3-p125/gems/scribbler-0.0.1/templates/2.rb]

Returns Array of Strings of the gem’s template files



32
33
34
# File 'lib/scribbler/configurator.rb', line 32

def templates
  Dir.glob(File.join(gem_path, 'templates', '*'))
end