epitools 0.4.4 → 0.4.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["epitron"]
12
- s.date = %q{2011-01-15}
12
+ s.date = %q{2011-01-20}
13
13
  s.description = %q{Miscellaneous utility libraries to make my life easier.}
14
14
  s.email = %q{chris@ill-logic.com}
15
15
  s.extra_rdoc_files = [
File without changes
@@ -35,6 +35,7 @@ class CacheDB
35
35
  url = page.uri.to_s
36
36
 
37
37
  p [:page_uri, url]
38
+ p [:original_url, url]
38
39
 
39
40
  if url != original_url
40
41
  # redirect original_url to url
@@ -48,7 +49,7 @@ class CacheDB
48
49
  )
49
50
  end
50
51
 
51
- compressed_body = Zlib::Deflate.deflate(page.body)
52
+ compressed_body = page.body #Zlib::Deflate.deflate(page.body)
52
53
  expire(url) if options[:overwrite]
53
54
  db.execute(
54
55
  "INSERT INTO cache VALUES ( ?, ?, ?, ? )",
@@ -71,7 +72,7 @@ class CacheDB
71
72
  if redirect
72
73
  get(redirect)
73
74
  else
74
- body = Zlib::Inflate.inflate(compressed_body)
75
+ body = compressed_body #Zlib::Inflate.inflate(compressed_body)
75
76
 
76
77
  Mechanize::Page.new(
77
78
  URI.parse(url),
@@ -150,6 +151,10 @@ class CacheDB
150
151
  create_tables
151
152
  end
152
153
 
154
+ def delete!
155
+ File.unlink @filename
156
+ end
157
+
153
158
  private
154
159
 
155
160
  def list_tables
@@ -16,7 +16,30 @@ class String
16
16
  end
17
17
 
18
18
  #
19
- # Output to less.
19
+ # Create scrollable output via less!
20
+ #
21
+ # This command runs `less` in a subprocess, and gives you the IO to its STDIN pipe
22
+ # so that you can communicate with it.
23
+ #
24
+ # Example:
25
+ #
26
+ # lesspipe do |less|
27
+ # 50.times { less.puts "Hi mom!" }
28
+ # end
29
+ #
30
+ # The default less parameters are:
31
+ # * Allow colour
32
+ # * Don't wrap lines longer than the screen
33
+ # * Quit immediately (without paging) if there's less than one screen of text.
34
+ #
35
+ # You can change these options by passing a hash to `lesspipe`, like so:
36
+ #
37
+ # lesspipe(:wrap=>false) { |less| less.puts essay.to_s }
38
+ #
39
+ # It accepts the following boolean options:
40
+ # :color => Allow ANSI colour codes?
41
+ # :wrap => Wrap long lines?
42
+ # :always => Always page, even if there's less than one page of text?
20
43
  #
21
44
  def lesspipe(*args)
22
45
  if args.any? and args.last.is_a?(Hash)
@@ -41,3 +64,57 @@ def lesspipe(*args)
41
64
  end
42
65
  end
43
66
  end
67
+
68
+
69
+ #
70
+ # Execute a `system()` command using SQL-style escaped arguments.
71
+ #
72
+ # Example:
73
+ # cmd( ["cp -arv ? ?", "/usr/src", "/home/you/A Folder/dest"] )
74
+ #
75
+ # Which is equivalent to:
76
+ # system( "cp", "-arv", "/usr/src", "/home/you/A Folder/dest" )
77
+ #
78
+ # Notice that you don't need to shell-escape anything.
79
+ # That's done automagically!
80
+ #
81
+ # If you don't pass any arrays, `cmd` works the same as `system`:
82
+ # cmd( "cp", "-arv", "etc", "etc" )
83
+ #
84
+ def cmd(*args)
85
+
86
+ cmd_args = []
87
+
88
+ for arg in args
89
+
90
+ case arg
91
+
92
+ when Array
93
+ cmd_literals = arg.shift.split(/\s+/)
94
+
95
+ for cmd_literal in cmd_literals
96
+ if cmd_literal == "?"
97
+ raise "Not enough substitution arguments" unless cmd_args.any?
98
+ cmd_args << arg.shift
99
+ else
100
+ cmd_args << cmd_literal
101
+ end
102
+ end
103
+
104
+ raise "More parameters than ?'s in cmd string" if arg.any?
105
+
106
+ when String
107
+ cmd_args << arg
108
+
109
+ else
110
+ cmd_args << arg.to_s
111
+
112
+ end
113
+
114
+ end
115
+
116
+ p [:cmd_args, cmd_args] if $DEBUG
117
+
118
+ system(*cmd_args)
119
+ end
120
+
File without changes
@@ -1,5 +1,4 @@
1
- require 'epitools/basetypes'
2
-
1
+ rrequire 'epitools/basetypes'
3
2
 
4
3
  describe Object do
5
4
 
@@ -1,14 +1,71 @@
1
1
  require 'epitools/browser'
2
2
 
3
- describe Browser do
3
+ #describe Browser do
4
+ #
5
+ # before :all do
6
+ # @browser = Browser.new
7
+ # end
8
+ #
9
+ # after :all do
10
+ # @browser.cache.delete!
11
+ # end
12
+ #
13
+ # it "googles" do
14
+ # page = @browser.get("http://google.com")
15
+ # page.body["Feeling Lucky"].should_not be_empty
16
+ # end
17
+ #
18
+ #end
19
+
20
+ class Mechanize::Page
21
+ def url
22
+ uri.to_s
23
+ end
24
+ end
25
+
26
+ describe CacheDB do
4
27
 
5
28
  before :all do
6
- @browser = Browser.new
29
+ @agent = Mechanize.new
30
+ CacheDB.new(@agent).delete!
31
+ @cache = CacheDB.new(@agent)
32
+ end
33
+
34
+ def new_page(body, url)
35
+ Mechanize::Page.new(
36
+ URI.parse(url),
37
+ {'content-type'=>'text/html'},
38
+ body,
39
+ nil,
40
+ @agent
41
+ )
42
+ end
43
+
44
+ after :all do
45
+ #@cache.delete!
7
46
  end
8
-
9
- it "googles" do
10
- page = @browser.get("http://google.com")
11
- page.body["Feeling Lucky"].should_not be_empty
47
+
48
+ it "writes and reads" do
49
+ body = "Blah blah blah."
50
+ url = "http://example.com/url.html"
51
+
52
+ page = new_page(body, url)
53
+
54
+ page.body.should == body
55
+ page.url.should == url
56
+
57
+ @cache.put page, url
58
+
59
+ p @cache.urls
60
+
61
+ @cache.includes?(url).should == true
62
+
63
+ result = @cache.get url
64
+
65
+ body.should == page.body
66
+ body.should == result.body
67
+ url.should == page.url
68
+ url.should == result.url
12
69
  end
13
70
 
14
71
  end
@@ -12,4 +12,14 @@ describe String do
12
12
  "xxxmatchzzz".highlight(/MATCH/i, color).should == highlighted
13
13
  end
14
14
 
15
+ it "cmds" do
16
+ cmd( ['test -f ?', __FILE__] ).should == true
17
+ cmd( ['test -d ?', __FILE__] ).should == false
18
+ cmd( "test", "-f", __FILE__ ).should == true
19
+ cmd( "test", "-d", __FILE__ ).should == false
20
+
21
+ lambda { cmd( ["test -f ? ?", __FILE__] ) }.should raise_error # too many ?'s
22
+ lambda { cmd( ["test -f", __FILE__] ) }.should raise_error # too few ?'s
23
+ end
24
+
15
25
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 4
9
- - 4
10
- version: 0.4.4
8
+ - 5
9
+ version: 0.4.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - epitron
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-15 00:00:00 -05:00
17
+ date: 2011-01-20 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 7
30
28
  segments:
31
29
  - 2
32
30
  - 2
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 23
46
43
  segments:
47
44
  - 1
48
45
  - 0
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 3
62
58
  segments:
63
59
  - 0
64
60
  version: "0"
@@ -129,7 +125,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
125
  requirements:
130
126
  - - ">="
131
127
  - !ruby/object:Gem::Version
132
- hash: 3
133
128
  segments:
134
129
  - 0
135
130
  version: "0"
@@ -138,7 +133,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
133
  requirements:
139
134
  - - ">="
140
135
  - !ruby/object:Gem::Version
141
- hash: 3
142
136
  segments:
143
137
  - 0
144
138
  version: "0"