-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sc - starting out with some better inspection tools to be more produc…
…tive working with cocoa
- Loading branch information
Showing
14 changed files
with
343 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,38 @@ | |||
class Object | |||
def singleton_class | |||
(class << self; self; end) | |||
end | |||
end | |||
|
|||
class Decorator | |||
def before(&block) | |||
@before = block | |||
end | |||
|
|||
def after(&block) | |||
@after = block | |||
end | |||
|
|||
def apply_to(subject) | |||
before_block = @before | |||
after_block = @after | |||
|
|||
subject.public_methods(false).each do |method| | |||
next if method == "inspect" | |||
subject.singleton_class.class_eval do | |||
original_method_symbol = "original_#{method}".to_sym | |||
alias_method original_method_symbol, method | |||
|
|||
define_method(method) do |*args| | |||
before_block.call(method.to_sym, args) if before_block | |||
|
|||
result = subject.send(original_method_symbol, *args) | |||
|
|||
after_block.call(method.to_sym, args, result) if after_block | |||
|
|||
result | |||
end | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
require "lib/decorator" | |||
|
|||
class LogDecorator | |||
def initialize(stream) | |||
@stream = stream | |||
end | |||
|
|||
def apply_to(subject) | |||
the_stream = @stream | |||
|
|||
decorator = Decorator.new | |||
decorator.before do |method_symbol, args| | |||
the_stream << "-> #{subject.class}.#{method_symbol.to_s}#{_args_to_s(args)}\n" | |||
end | |||
decorator.after do |method_symbol, args, result| | |||
the_stream << "<- #{subject.class}.#{method_symbol.to_s}#{_args_to_s(args)} : #{result.inspect}\n" | |||
end | |||
|
|||
decorator.apply_to(subject) | |||
end | |||
|
|||
def _args_to_s(args) | |||
if args.length > 0 | |||
"(" + args.collect{|arg|arg.class.to_s}.join(", ") + ")" | |||
else | |||
"" | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
Gem::Specification.new do |s| | |||
s.name = %q{schnauzer} | |||
s.version = "0.1" | |||
|
|||
s.authors = ["Steve Conover"] | |||
s.date = %q{2009-02-24} | |||
s.description = %q{A real Safari browser in ruby} | |||
s.email = %q{sconover@gmail.com} | |||
s.extensions = [] | |||
s.extra_rdoc_files = ["README", "LICENSE"] | |||
s.files = [] | |||
s.has_rdoc = true | |||
s.homepage = %q{http://github.com/sconover/schnauzer/tree/master} | |||
s.rdoc_options = ["--quiet", "--title", "Schnauzer", "--main", "README", "--inline-source"] | |||
s.require_paths = ["lib"] | |||
s.summary = %q{A real Safari browser in ruby. You can provide your own url request/response handling. It's fast.} | |||
s.add_dependency "sinatra" | |||
s.add_dependency "rubycocoa" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.