scribbler 0.1.3 → 0.2.3
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/lib/scribbler/base.rb +1 -29
- data/lib/scribbler/configurator.rb +0 -14
- data/lib/scribbler/includeables.rb +24 -21
- data/lib/scribbler/version.rb +1 -1
- data/spec/scribbler/base_spec.rb +2 -18
- data/templates/scribbler.rb +0 -14
- metadata +4 -4
data/lib/scribbler/base.rb
CHANGED
@@ -64,7 +64,6 @@ module Scribbler
|
|
64
64
|
class_eval(&block)
|
65
65
|
Base.include_in_application
|
66
66
|
BaseIncluder.include_includeables
|
67
|
-
build_methods
|
68
67
|
end
|
69
68
|
|
70
69
|
# Simply returns the configurator class.
|
@@ -162,7 +161,7 @@ module Scribbler
|
|
162
161
|
# Returns Nothing
|
163
162
|
def self.apply_to_log(location, options={})
|
164
163
|
if can_apply_to_log? location, options
|
165
|
-
File.open(
|
164
|
+
File.open log_at(location), 'a' do |f|
|
166
165
|
f.puts build_with_template(options)
|
167
166
|
end
|
168
167
|
end
|
@@ -176,33 +175,6 @@ module Scribbler
|
|
176
175
|
options[:custom_fields].present?)
|
177
176
|
end
|
178
177
|
|
179
|
-
# Attempts to turn a symbol or string into the *_log_location method that
|
180
|
-
# was auto-build based on Configurator.logs and finds the file path
|
181
|
-
#
|
182
|
-
# location - a string or symbol that will be turned into a *_log_location
|
183
|
-
# method
|
184
|
-
#
|
185
|
-
# Examples
|
186
|
-
#
|
187
|
-
# Base.find_file_at :a_file
|
188
|
-
# # => <#Path:...> # The method `a_file_log_location` exists
|
189
|
-
#
|
190
|
-
# Base.find_file_at :another_file
|
191
|
-
# # => :another_file # The method `another_file_log_location` does not exist
|
192
|
-
#
|
193
|
-
# Returns Nothing
|
194
|
-
def self.find_file_at(location)
|
195
|
-
if location.is_a?(Symbol) or location.is_a?(String)
|
196
|
-
real_method = location.to_s + "_log_location"
|
197
|
-
if respond_to?(real_method)
|
198
|
-
location = send(real_method)
|
199
|
-
else
|
200
|
-
location = "#{config.log_directory.to_s}/#{location.to_s}"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
location
|
204
|
-
end
|
205
|
-
|
206
178
|
# If the config agrees, attempt to include our special methods
|
207
179
|
# in the main application object.
|
208
180
|
#
|
@@ -22,20 +22,6 @@ module Scribbler
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# List of strings or symbols that represent logs we want methods
|
26
|
-
# generated for
|
27
|
-
#
|
28
|
-
# Default: []
|
29
|
-
#
|
30
|
-
# Examples
|
31
|
-
#
|
32
|
-
# Scribbler::Configurator.logs
|
33
|
-
# # => ['copy', 'destroy']
|
34
|
-
#
|
35
|
-
# Returns list of logs
|
36
|
-
def self.logs
|
37
|
-
@logs ||= []
|
38
|
-
end
|
39
25
|
|
40
26
|
# Boolean used for deciding whether or not Scribbler should
|
41
27
|
# define #*_log_location methods and a .log method in a rails application
|
@@ -17,29 +17,32 @@ module Scribbler
|
|
17
17
|
|
18
18
|
module Includeables
|
19
19
|
extend ActiveSupport::Concern
|
20
|
+
module ClassMethods
|
21
|
+
def log_location_regex
|
22
|
+
/(?<file>.*)_log_location$/
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
# Public: defines methods for log location. The first element
|
26
|
+
# defines the prefix for the method so "subseason" = subseason_log_location.
|
27
|
+
# The second element defines the name of the logfile so "subseason" =
|
28
|
+
# root_of_app/log/subseason.log
|
29
|
+
#
|
30
|
+
# Examples
|
31
|
+
#
|
32
|
+
# subseason_log_location
|
33
|
+
# # => #<Pathname:/path_to_ngin/log/subseason_copy_structure.log>
|
34
|
+
#
|
35
|
+
# Returns Pathname to log
|
36
|
+
def method_missing(name, *args, &block)
|
37
|
+
(match = name.to_s.match log_location_regex) ? log_at(match[:file]) : super
|
38
|
+
end
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
# Examples
|
33
|
-
#
|
34
|
-
# subseason_log_location
|
35
|
-
# # => #<Pathname:/path_to_ngin/log/subseason_copy_structure.log>
|
36
|
-
#
|
37
|
-
# Returns Pathname to log
|
38
|
-
Scribbler::Base.config.logs.each do |value|
|
39
|
-
define_singleton_method "#{value}_log_location" do
|
40
|
-
File.join Scribbler::Configurator.log_directory, "#{value}.log"
|
41
|
-
end
|
42
|
-
end
|
40
|
+
def respond_to?(name)
|
41
|
+
(m = name.to_s.match log_location_regex) ? !!m : super
|
42
|
+
end
|
43
|
+
|
44
|
+
def log_at(file_name)
|
45
|
+
File.join Scribbler::Configurator.log_directory, "#{file_name}.log"
|
43
46
|
end
|
44
47
|
|
45
48
|
# Public: Save ourselves some repetition. Notifies error to NewRelic
|
data/lib/scribbler/version.rb
CHANGED
data/spec/scribbler/base_spec.rb
CHANGED
@@ -35,7 +35,6 @@ module Scribbler
|
|
35
35
|
describe "configure" do
|
36
36
|
it "kicks off the module and sends includes" do
|
37
37
|
subject.should_receive(:include_in_application).once
|
38
|
-
subject.should_receive(:build_methods).once # Twice if we didn't stub below method
|
39
38
|
BaseIncluder.should_receive(:include_includeables).once
|
40
39
|
subject.configure do
|
41
40
|
end
|
@@ -124,32 +123,17 @@ module Scribbler
|
|
124
123
|
options = { :message => "..." }
|
125
124
|
file = mock(:puts => true)
|
126
125
|
subject.should_receive(:build_with_template).with options
|
127
|
-
subject.should_receive(:
|
126
|
+
subject.should_receive(:log_at).with :test_log
|
128
127
|
File.should_receive(:open).and_yield(file)
|
129
128
|
subject.apply_to_log :test_log, options
|
130
129
|
end
|
131
|
-
end
|
132
130
|
|
133
|
-
describe "find file at" do
|
134
131
|
it "doesn't find a file method" do
|
135
132
|
# in case we have bad config data lingering
|
136
133
|
subject.stub(:respond_to?).with('test_log_log_location').and_return false
|
137
134
|
subject.should_not_receive(:test_log_log_location)
|
138
135
|
Rails.should_receive(:root).and_raise(NameError)
|
139
|
-
subject.
|
140
|
-
end
|
141
|
-
|
142
|
-
it "finds a file method defined" do
|
143
|
-
subject.configure do
|
144
|
-
config.logs = %w[test_log]
|
145
|
-
end
|
146
|
-
subject.should_receive(:test_log_log_location).once
|
147
|
-
subject.find_file_at :test_log
|
148
|
-
end
|
149
|
-
|
150
|
-
it "isn't a string or a symbol and just returns the input" do
|
151
|
-
path = Pathname.new '/'
|
152
|
-
subject.find_file_at(path).should be(path)
|
136
|
+
subject.log_at(:test_log).should == "#{subject.config.log_directory}/test_log.log"
|
153
137
|
end
|
154
138
|
end
|
155
139
|
end
|
data/templates/scribbler.rb
CHANGED
@@ -15,20 +15,6 @@ Scribbler::Base.configure do
|
|
15
15
|
#
|
16
16
|
# config.log_directory = File.new '/a/better/path'
|
17
17
|
#
|
18
|
-
#
|
19
|
-
# A list of the logs you'd like location methods for. if the logs list
|
20
|
-
# has:
|
21
|
-
#
|
22
|
-
# ['log1']
|
23
|
-
#
|
24
|
-
# You are afforded a Base.log1_log_location method and you may do:
|
25
|
-
#
|
26
|
-
# Base.log :log1, ....
|
27
|
-
#
|
28
|
-
# REQUIRED
|
29
|
-
#
|
30
|
-
# config.logs = %w[log1 log2]
|
31
|
-
#
|
32
18
|
# This option enables log templating. Each time you log a message you
|
33
19
|
# can have it automatically wrapped in some sugar. The default is something
|
34
20
|
# like:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scribbler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash: -
|
143
|
+
hash: -3735178954186904383
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
none: false
|
146
146
|
requirements:
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
segments:
|
151
151
|
- 0
|
152
|
-
hash: -
|
152
|
+
hash: -3735178954186904383
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
155
|
rubygems_version: 1.8.24
|