mole 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -15,6 +15,8 @@ lib/mole/module.rb
15
15
  lib/mole/moler.rb
16
16
  lib/mole/utils/frameworks.rb
17
17
  lib/mole/version.rb
18
+ spec/config/mole_config.rb
19
+ spec/config/moles/fred_config.rb
18
20
  spec/data/blee.rb
19
21
  spec/db/migrate_spec.rb
20
22
  spec/emole_spec.rb
data/README.txt CHANGED
@@ -86,7 +86,19 @@ The MOle allows you to easily
86
86
  :log_file => $stdout,
87
87
  :log_level => :debug,
88
88
  :perf_threshold => 2,
89
- :mole_config => File.join( File.dirname(__FILE__), %w[mole.rb] ) )
89
+ :mole_config => File.join( File.dirname(__FILE__), %w[mole.rb] ) )
90
+ # Load the MOle configuration file(s)
91
+ ::Mole.load_configuration
92
+
93
+ NOTE: The mole_config can either be a single ruby file or a directory containing multiple MOle
94
+ configuration files. Thanks to Ian Schreuder for the suggestion !
95
+
96
+ NOTE: For rails application you can either put the MOle initialization code in a custom initializer
97
+ or in your environment file ie config/environments/production.rb. You will need to make the
98
+ load_configuration call in your application controller as follows:
99
+
100
+ ::Mole.load_mole_configuration rescue nil
101
+
90
102
 
91
103
  * Now you'll need to create a mole.rb specification file to specify the various aspects you'll want
92
104
  to inject. This file is specified in the initialize call via the :mole_config tag.
data/lib/mole/version.rb CHANGED
@@ -2,7 +2,7 @@ module Mole
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  # Returns the version string for the library.
8
8
  #
data/lib/mole.rb CHANGED
@@ -66,15 +66,30 @@ unless defined? Mole
66
66
  def self.initialize( opts={} )
67
67
  @config = defaults.merge( opts )
68
68
  @config[:email_alerts_to] = @config[:emole_recipients] if @config[:emole_recipients] and !@config[:emole_recipients].empty?
69
- # dump
70
- # Add the mode to the ruby lib path...
69
+ # Add the mole/lib to the ruby path...
71
70
  $: << libpath
72
- Mole.require_all_libs_relative_to __FILE__
73
-
74
- raise "Unable to find the MOle configuration file #{conf_file}" if conf_file and !File.exists? conf_file
75
- load conf_file if conf_file and moleable?
71
+ Mole.require_all_libs_relative_to __FILE__
76
72
  end
77
73
 
74
+ # Loads the mole configuration file
75
+ # You can either specify a directory containing mole config files or
76
+ # a single mole config file via the mole_config option.
77
+ def self.load_mole_configuration
78
+ return unless moleable?
79
+ raise "Unable to find the MOle configuration from `#{conf_file}" if conf_file and !File.exists? conf_file
80
+ unless @config_loaded
81
+ @config_loader = true
82
+ if File.directory? conf_file
83
+ logger.debug "--- Loading MOle configs files from directory `#{conf_file}"
84
+ load_all_moles_relative_to( conf_file )
85
+ else
86
+ logger.debug "--- Loading single MOle config #{conf_file}"
87
+ load conf_file
88
+ end
89
+ end
90
+ @config_loaded
91
+ end
92
+
78
93
  # Fetch the MOle configuration file
79
94
  def self.conf_file #:nodoc:
80
95
  config[:mole_config]
@@ -158,17 +173,25 @@ unless defined? Mole
158
173
  args.empty? ? PATH : ::File.join(PATH, *args)
159
174
  end
160
175
 
161
- # Utility method used to rquire all files ending in .rb that lie in the
176
+ # Utility method used to require all files ending in .rb that lie in the
162
177
  # directory below this file that has the same name as the filename passed
163
178
  # in. Optionally, a specific _directory_ name can be passed in such that
164
179
  # the _filename_ does not have to be equivalent to the directory.
165
180
  #
166
181
  def self.require_all_libs_relative_to( fname, dir = nil ) #:nodoc:
167
- dir ||= ::File.basename(fname, '.*')
168
- search_me = ::File.expand_path(
169
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
170
-
182
+ dir ||= ::File.basename(fname, '.*')
183
+ search_me = ::File.expand_path( ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
171
184
  Dir.glob(search_me).sort.each {|rb| require rb}
172
185
  end
186
+
187
+ # Utility method used to load all MOle config files ending in .rb that lie in the
188
+ # directory below this file that has the same name as the filename passed
189
+ # in. Optionally, a specific _directory_ name can be passed in such that
190
+ # the _filename_ does not have to be equivalent to the directory.
191
+ #
192
+ def self.load_all_moles_relative_to( mole_dir ) #:nodoc:
193
+ search_me = ::File.join( mole_dir, '**', '*.rb')
194
+ Dir.glob(search_me).sort.each {|rb| logger.debug "---- Loading MOle config '#{rb}'";load rb}
195
+ end
173
196
  end
174
197
  end
File without changes
File without changes
data/spec/mole_spec.rb CHANGED
@@ -35,4 +35,32 @@ describe Mole do
35
35
  Mole.dump
36
36
  end
37
37
 
38
+ describe "load_mole_configuration" do
39
+ before( :each ) do
40
+ ::Mole.reset_configuration!
41
+ end
42
+
43
+ it "should load single file correctly" do
44
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config mole_config.rb] ) )
45
+ ::Mole.load_mole_configuration
46
+ require( File.join( File.dirname(__FILE__), %w[config mole_config.rb] ) ).should == []
47
+ end
48
+
49
+ it "should load config for directory correctly" do
50
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config moles] ) )
51
+ ::Mole.load_mole_configuration
52
+ require( File.join( File.dirname(__FILE__), %w[config moles fred_config.rb] ) ).should == []
53
+ end
54
+
55
+ it "should raise an error if the configuration file does not exist" do
56
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config fred_mole.rb] ) )
57
+ lambda{ ::Mole.load_mole_configuration }.should raise_error( "Unable to find the MOle configuration from `./spec/config/fred_mole.rb" )
58
+ end
59
+
60
+ it "should raise an error if the config directory does not exist" do
61
+ ::Mole.initialize( :moleable => true, :mole_config => File.join( File.dirname(__FILE__), %w[config freds] ) )
62
+ lambda{ ::Mole.load_mole_configuration }.should raise_error( "Unable to find the MOle configuration from `./spec/config/freds" )
63
+ end
64
+ end
65
+
38
66
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: mole
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.4
7
- date: 2008-03-06 00:00:00 -07:00
6
+ version: 1.0.5
7
+ date: 2008-03-25 00:00:00 -06:00
8
8
  summary: A flexible way to track user's interactions within your ruby web applications
9
9
  require_paths:
10
10
  - lib
@@ -46,6 +46,8 @@ files:
46
46
  - lib/mole/moler.rb
47
47
  - lib/mole/utils/frameworks.rb
48
48
  - lib/mole/version.rb
49
+ - spec/config/mole_config.rb
50
+ - spec/config/moles/fred_config.rb
49
51
  - spec/data/blee.rb
50
52
  - spec/db/migrate_spec.rb
51
53
  - spec/emole_spec.rb