clogger 0.7.0 → 0.8.0

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/.gitignore CHANGED
@@ -16,3 +16,4 @@ Makefile
16
16
  /NEWS
17
17
  /GIT-VERSION-FILE
18
18
  /LATEST
19
+ /tmp
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.7.0.GIT
4
+ DEF_VER=v0.8.0.GIT
5
5
 
6
6
  LF='
7
7
  '
data/GNUmakefile CHANGED
@@ -1,143 +1,18 @@
1
- all:: test
2
- RUBY = ruby
3
- RAKE = rake
4
- RSYNC = rsync
5
-
6
- GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
7
- @./GIT-VERSION-GEN
8
- -include GIT-VERSION-FILE
9
- -include local.mk
10
-
11
- ifeq ($(DLEXT),) # "so" for Linux
12
- DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
13
- endif
14
-
15
- ext/clogger_ext/Makefile: ext/clogger_ext/clogger.c ext/clogger_ext/extconf.rb
16
- cd ext/clogger_ext && $(RUBY) extconf.rb
17
-
18
- ext/clogger_ext/clogger.$(DLEXT): ext/clogger_ext/Makefile
19
- $(MAKE) -C ext/clogger_ext
20
-
21
- clean:
22
- -$(MAKE) -C ext/clogger_ext clean
23
- $(RM) ext/clogger_ext/Makefile lib/clogger_ext.$(DLEXT)
24
-
25
- test_unit := $(wildcard test/test_*.rb)
26
- test-unit: $(test_unit)
27
-
28
- ifeq ($(CLOGGER_PURE),)
29
- $(test_unit): mylib := ext/clogger_ext:lib
30
- $(test_unit): ext/clogger_ext/clogger.$(DLEXT)
31
- else
32
- $(test_unit): mylib := lib
33
- endif
34
-
35
- $(test_unit):
36
- $(RUBY) -I $(mylib) $@
37
-
1
+ all::
2
+ RSYNC_DEST := rubyforge.org:/var/www/gforge-projects/clogger/
3
+ rfproject := clogger
4
+ rfpackage := clogger
5
+ include pkg.mk
38
6
  test-ext:
39
7
  CLOGGER_PURE= $(MAKE) test-unit
40
-
41
8
  test-pure:
42
9
  CLOGGER_PURE=1 $(MAKE) test-unit
43
10
 
44
11
  test: test-ext test-pure
45
12
 
46
- pkg_extra := GIT-VERSION-FILE NEWS ChangeLog LATEST
47
- manifest: $(pkg_extra)
48
- $(RM) .manifest
49
- $(MAKE) .manifest
50
-
51
- .manifest:
52
- (git ls-files && \
53
- for i in $@ $(pkg_extra); \
54
- do echo $$i; done) | LC_ALL=C sort > $@+
55
- cmp $@+ $@ || mv $@+ $@
56
- $(RM) $@+
57
-
58
- ChangeLog: GIT-VERSION-FILE .wrongdoc.yml
59
- wrongdoc prepare
60
-
61
- doc: .document .wrongdoc.yml
62
- find lib ext -type f -name '*.rbc' -exec rm -f '{}' ';'
63
- $(RM) -r doc
64
- wrongdoc all
65
- install -m644 COPYING doc/COPYING
66
- install -m644 $(shell grep '^[A-Z]' .document) doc/
67
-
68
- # publishes docs to http://clogger.rubyforge.org/
69
- # this preserves timestamps as best as possible to help HTTP caches out
70
- # git set-file-times is here: http://git-scm.org/gitwiki/ExampleScripts
71
- publish_doc:
72
- -git set-file-times
73
- $(MAKE) doc
74
- -find doc/images -type f | \
75
- TZ=UTC xargs touch -d '1970-01-01 00:00:03' doc/rdoc.css
76
- $(RSYNC) -av doc/ rubyforge.org:/var/www/gforge-projects/clogger/
77
- git ls-files | xargs touch
78
-
13
+ .PHONY: test-ext test-pure
79
14
  ifneq ($(VERSION),)
80
- rfproject := clogger
81
- rfpackage := clogger
82
- pkggem := pkg/$(rfpackage)-$(VERSION).gem
83
- pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
84
- release_notes := release_notes-$(VERSION)
85
- release_changes := release_changes-$(VERSION)
86
-
87
- release-notes: $(release_notes)
88
- release-changes: $(release_changes)
89
- $(release_changes):
90
- wrongdoc release_changes > $@+
91
- $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
92
- $(release_notes):
93
- wrongdoc release_notes > $@+
94
- $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
95
-
96
- # ensures we're actually on the tagged $(VERSION), only used for release
97
- verify:
98
- test x"$(shell umask)" = x0022
99
- git rev-parse --verify refs/tags/v$(VERSION)^{}
100
- git diff-index --quiet HEAD^0
101
- test `git rev-parse --verify HEAD^0` = \
102
- `git rev-parse --verify refs/tags/v$(VERSION)^{}`
103
-
104
- fix-perms:
105
- -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
106
- -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
107
-
108
- gem: $(pkggem)
109
-
110
- install-gem: $(pkggem)
111
- gem install $(CURDIR)/$<
112
-
113
- $(pkggem): manifest fix-perms
114
- gem build $(rfpackage).gemspec
115
- mkdir -p pkg
116
- mv $(@F) $@
117
-
118
- $(pkgtgz): distdir = $(basename $@)
119
- $(pkgtgz): HEAD = v$(VERSION)
120
- $(pkgtgz): manifest fix-perms
121
- @test -n "$(distdir)"
122
- $(RM) -r $(distdir)
123
- mkdir -p $(distdir)
124
- tar cf - `cat .manifest` | (cd $(distdir) && tar xf -)
125
- cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
126
- mv $@+ $@
127
-
128
- package: $(pkgtgz) $(pkggem)
129
-
130
- release: verify package $(release_notes) $(release_changes)
131
- rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
132
- $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
133
- gem push $(pkggem)
134
- rubyforge add_file \
135
- $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
15
+ release::
136
16
  $(RAKE) publish_news VERSION=$(VERSION)
137
- else
138
- gem install-gem: GIT-VERSION-FILE
139
- $(MAKE) $@ VERSION=$(GIT_VERSION)
17
+ $(RAKE) raa_update VERSION=$(VERSION)
140
18
  endif
141
-
142
- .PHONY: .FORCE-GIT-VERSION-FILE test doc manifest
143
- .PHONY: test test-ext test-pure $(test_unit)
@@ -908,6 +908,30 @@ static VALUE to_path(VALUE self)
908
908
  return path;
909
909
  }
910
910
 
911
+ /*
912
+ * call-seq:
913
+ * clogger.to_io
914
+ *
915
+ * used to proxy +:to_io+ method calls to the wrapped response body.
916
+ */
917
+ static VALUE to_io(VALUE self)
918
+ {
919
+ struct clogger *c = clogger_get(self);
920
+ struct stat sb;
921
+ VALUE io = rb_convert_type(c->body, T_FILE, "IO", "to_io");
922
+
923
+ if (fstat(my_fileno(io), &sb) == 0)
924
+ c->body_bytes_sent = sb.st_size;
925
+
926
+ return io;
927
+ }
928
+
929
+ /* :nodoc: */
930
+ static VALUE body(VALUE self)
931
+ {
932
+ return clogger_get(self)->body;
933
+ }
934
+
911
935
  void Init_clogger_ext(void)
912
936
  {
913
937
  VALUE tmp;
@@ -938,7 +962,9 @@ void Init_clogger_ext(void)
938
962
  rb_define_method(cClogger, "wrap_body?", clogger_wrap_body, 0);
939
963
  rb_define_method(cClogger, "reentrant?", clogger_reentrant, 0);
940
964
  rb_define_method(cClogger, "to_path", to_path, 0);
965
+ rb_define_method(cClogger, "to_io", to_io, 0);
941
966
  rb_define_method(cClogger, "respond_to?", respond_to, 1);
967
+ rb_define_method(cClogger, "body", body, 0);
942
968
  CONST_GLOBAL_STR(REMOTE_ADDR);
943
969
  CONST_GLOBAL_STR(HTTP_X_FORWARDED_FOR);
944
970
  CONST_GLOBAL_STR(REQUEST_METHOD);
data/lib/clogger.rb CHANGED
@@ -4,8 +4,8 @@ require 'rack'
4
4
  # See the README for usage instructions
5
5
  class Clogger
6
6
 
7
- # the version of Clogger, currently 0.7.0
8
- VERSION = '0.7.0'
7
+ # the version of Clogger, currently 0.8.0
8
+ VERSION = '0.8.0'
9
9
 
10
10
  # :stopdoc:
11
11
  OP_LITERAL = 0
@@ -140,6 +140,10 @@ private
140
140
  end
141
141
  end
142
142
 
143
+ private
144
+ def method_missing(*args, &block)
145
+ body.__send__(*args, &block)
146
+ end
143
147
  # :startdoc:
144
148
  end
145
149
 
data/lib/clogger/pure.rb CHANGED
@@ -10,7 +10,7 @@ class Clogger
10
10
 
11
11
  def initialize(app, opts = {})
12
12
  # trigger autoload to avoid thread-safety issues later on
13
- Rack::Utils::HeaderHash.new({})
13
+ Rack::Utils::HeaderHash
14
14
 
15
15
  @app = app
16
16
  @logger = opts[:logger]
@@ -89,6 +89,10 @@ class Clogger
89
89
  rv
90
90
  end
91
91
 
92
+ def to_io
93
+ @body.to_io
94
+ end
95
+
92
96
  private
93
97
 
94
98
  def byte_xs(s)
data/pkg.mk ADDED
@@ -0,0 +1,166 @@
1
+ RUBY = ruby
2
+ RAKE = rake
3
+ RSYNC = rsync
4
+
5
+ GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
6
+ @./GIT-VERSION-GEN
7
+ -include GIT-VERSION-FILE
8
+ -include local.mk
9
+ DLEXT := $(shell $(RUBY) -rrbconfig -e 'puts Config::CONFIG["DLEXT"]')
10
+ RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
11
+ RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
12
+ lib := lib
13
+
14
+ ifeq ($(shell test -f script/isolate_for_tests && echo t),t)
15
+ isolate_libs := tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION)/isolate.mk
16
+ $(isolate_libs): script/isolate_for_tests
17
+ @$(RUBY) script/isolate_for_tests
18
+ -include $(isolate_libs)
19
+ lib := $(lib):$(ISOLATE_LIBS)
20
+ endif
21
+
22
+ ext := $(firstword $(wildcard ext/*))
23
+ ifneq ($(ext),)
24
+ ext_pfx := tmp/ext/$(RUBY_ENGINE)-$(RUBY_VERSION)
25
+ ext_h := $(wildcard $(ext)/*/*.h $(ext)/*.h)
26
+ ext_src := $(wildcard $(ext)/*.c $(ext_h))
27
+ ext_pfx_src := $(addprefix $(ext_pfx)/,$(ext_src))
28
+ ext_d := $(ext_pfx)/$(ext)/.d
29
+ $(ext)/extconf.rb: $(wildcard $(ext)/*.h)
30
+ @>> $@
31
+ $(ext_d):
32
+ @mkdir -p $(@D)
33
+ @> $@
34
+ $(ext_pfx)/$(ext)/%: $(ext)/% $(ext_d)
35
+ install -m 644 $< $@
36
+ $(ext_pfx)/$(ext)/Makefile: $(ext)/extconf.rb $(ext_d) $(ext_h)
37
+ $(RM) -f $(@D)/*.o
38
+ cd $(@D) && $(RUBY) $(CURDIR)/$(ext)/extconf.rb
39
+ ext_sfx := _ext.$(DLEXT)
40
+ ext_dl := $(ext_pfx)/$(ext)/$(notdir $(ext)_ext.$(DLEXT))
41
+ $(ext_dl): $(ext_src) $(ext_pfx_src) $(ext_pfx)/$(ext)/Makefile
42
+ @echo $^ == $@
43
+ $(MAKE) -C $(@D)
44
+ lib := $(lib):$(ext_pfx)/$(ext)
45
+ build: $(ext_dl)
46
+ endif
47
+
48
+ pkg_extra := GIT-VERSION-FILE NEWS ChangeLog LATEST
49
+ ChangeLog: GIT-VERSION-FILE .wrongdoc.yml
50
+ wrongdoc prepare
51
+
52
+ manifest:
53
+ $(RM) .manifest
54
+ $(MAKE) .manifest
55
+
56
+ .manifest: ChangeLog
57
+ (git ls-files && for i in $@ $(pkg_extra); do echo $$i; done) | \
58
+ LC_ALL=C sort > $@+
59
+ cmp $@+ $@ || mv $@+ $@
60
+ $(RM) $@+
61
+
62
+ doc: .document .wrongdoc.yml
63
+ find lib ext -type f -name '*.rbc' -exec rm -f '{}' ';'
64
+ $(RM) -r doc
65
+ wrongdoc all
66
+ install -m644 COPYING doc/COPYING
67
+ install -m644 $(shell grep '^[A-Z]' .document) doc/
68
+
69
+ ifneq ($(VERSION),)
70
+ pkggem := pkg/$(rfpackage)-$(VERSION).gem
71
+ pkgtgz := pkg/$(rfpackage)-$(VERSION).tgz
72
+ release_notes := release_notes-$(VERSION)
73
+ release_changes := release_changes-$(VERSION)
74
+
75
+ release-notes: $(release_notes)
76
+ release-changes: $(release_changes)
77
+ $(release_changes):
78
+ wrongdoc release_changes > $@+
79
+ $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
80
+ $(release_notes):
81
+ wrongdoc release_notes > $@+
82
+ $(VISUAL) $@+ && test -s $@+ && mv $@+ $@
83
+
84
+ # ensures we're actually on the tagged $(VERSION), only used for release
85
+ verify:
86
+ test x"$(shell umask)" = x0022
87
+ git rev-parse --verify refs/tags/v$(VERSION)^{}
88
+ git diff-index --quiet HEAD^0
89
+ test $$(git rev-parse --verify HEAD^0) = \
90
+ $$(git rev-parse --verify refs/tags/v$(VERSION)^{})
91
+
92
+ fix-perms:
93
+ -git ls-tree -r HEAD | awk '/^100644 / {print $$NF}' | xargs chmod 644
94
+ -git ls-tree -r HEAD | awk '/^100755 / {print $$NF}' | xargs chmod 755
95
+
96
+ gem: $(pkggem)
97
+
98
+ install-gem: $(pkggem)
99
+ gem install $(CURDIR)/$<
100
+
101
+ $(pkggem): manifest fix-perms
102
+ gem build $(rfpackage).gemspec
103
+ mkdir -p pkg
104
+ mv $(@F) $@
105
+
106
+ $(pkgtgz): distdir = $(basename $@)
107
+ $(pkgtgz): HEAD = v$(VERSION)
108
+ $(pkgtgz): manifest fix-perms
109
+ @test -n "$(distdir)"
110
+ $(RM) -r $(distdir)
111
+ mkdir -p $(distdir)
112
+ tar cf - $$(cat .manifest) | (cd $(distdir) && tar xf -)
113
+ cd pkg && tar cf - $(basename $(@F)) | gzip -9 > $(@F)+
114
+ mv $@+ $@
115
+
116
+ package: $(pkgtgz) $(pkggem)
117
+
118
+ test-release:: verify package $(release_notes) $(release_changes)
119
+ # make tgz release on RubyForge
120
+ @echo rubyforge add_release -f \
121
+ -n $(release_notes) -a $(release_changes) \
122
+ $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
123
+ @echo gem push $(pkggem)
124
+ @echo rubyforge add_file \
125
+ $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
126
+ release:: verify package $(release_notes) $(release_changes)
127
+ # make tgz release on RubyForge
128
+ rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
129
+ $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
130
+ # push gem to RubyGems.org
131
+ gem push $(pkggem)
132
+ # in case of gem downloads from RubyForge releases page
133
+ rubyforge add_file \
134
+ $(rfproject) $(rfpackage) $(VERSION) $(pkggem)
135
+ else
136
+ gem install-gem: GIT-VERSION-FILE
137
+ $(MAKE) $@ VERSION=$(GIT_VERSION)
138
+ endif
139
+
140
+ all:: test
141
+ test_units := $(wildcard test/test_*.rb)
142
+ test: test-unit
143
+ test-unit: $(test_units)
144
+ $(test_units): build
145
+ $(RUBY) -I $(lib) $@
146
+
147
+ # this requires GNU coreutils variants
148
+ ifneq ($(RSYNC_DEST),)
149
+ publish_doc:
150
+ -git set-file-times
151
+ $(MAKE) doc
152
+ find doc/images -type f | \
153
+ TZ=UTC xargs touch -d '1970-01-01 00:00:06' doc/rdoc.css
154
+ $(MAKE) doc_gz
155
+ $(RSYNC) -av doc/ $(RSYNC_DEST)/
156
+ git ls-files | xargs touch
157
+ endif
158
+
159
+ # Create gzip variants of the same timestamp as the original so nginx
160
+ # "gzip_static on" can serve the gzipped versions directly.
161
+ doc_gz: docs = $(shell find doc -type f ! -regex '^.*\.\(gif\|jpg\|png\|gz\)$$')
162
+ doc_gz:
163
+ for i in $(docs); do \
164
+ gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
165
+
166
+ .PHONY: all .FORCE-GIT-VERSION-FILE doc test $(test_units) manifest
data/test/test_clogger.rb CHANGED
@@ -697,4 +697,32 @@ class TestClogger < Test::Unit::TestCase
697
697
  status, headers, body = cl.call(@req)
698
698
  assert %r!\A\d+/\w+/\d{4}:\d\d:\d\d:\d\d \+0000\n\z! =~ s[0], s.inspect
699
699
  end
700
+
701
+ def test_method_missing
702
+ s = []
703
+ body = []
704
+ def body.foo_bar(foo)
705
+ [ foo.to_s ]
706
+ end
707
+ def body.noargs
708
+ :hello
709
+ end
710
+ def body.omg(&block)
711
+ yield :PONIES
712
+ end
713
+ app = lambda { |env| [200, [], body ] }
714
+ cl = Clogger.new(app, :logger => s, :format => '$body_bytes_sent')
715
+ status, headers, body = cl.call(@req)
716
+ assert_nothing_raised do
717
+ body.each { |x| s << x }
718
+ body.close
719
+ end
720
+ assert_equal "0\n", s[0], s.inspect
721
+ assert_kind_of Clogger, body
722
+ assert_equal %w(1), body.foo_bar(1)
723
+ assert_equal :hello, body.noargs
724
+ body.omg { |x| s << x }
725
+ assert_equal :PONIES, s[1]
726
+ assert_equal 2, s.size
727
+ end
700
728
  end
@@ -120,7 +120,8 @@ class TestCloggerToPath < Test::Unit::TestCase
120
120
  assert_instance_of(Clogger, body)
121
121
  check_body(body)
122
122
 
123
- body.to_path
123
+ assert_equal tmp.path, body.to_path
124
+ assert_nothing_raised { body.to_io }
124
125
  assert_kind_of IO, tmp.instance_variable_get(:@to_io_called)
125
126
  assert logger.string.empty?
126
127
  assert ! tmp.closed?
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clogger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
8
+ - 8
9
9
  - 0
10
- version: 0.7.0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - cloggers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-15 00:00:00 +00:00
18
+ date: 2011-01-21 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - lib/clogger.rb
90
90
  - lib/clogger/format.rb
91
91
  - lib/clogger/pure.rb
92
+ - pkg.mk
92
93
  - setup.rb
93
94
  - test/test_clogger.rb
94
95
  - test/test_clogger_to_path.rb