rack-musicindex 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/rack/musicindex.rb +14 -8
- data/lib/rack/musicindex/version.rb +1 -1
- data/spec/rack/musicindex_spec.rb +35 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# rack-musicindex
|
2
2
|
|
3
3
|
A Rack middleware to publish directries containing media files as podcast
|
4
4
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
require 'rack-musicindex'
|
23
23
|
|
24
24
|
use Rack::MusicIndex, {
|
25
|
-
'/foo' => '/path/to/mp3s'
|
25
|
+
'/foo' => '/path/to/mp3s'
|
26
26
|
}
|
27
27
|
|
28
28
|
## Contributing
|
data/lib/rack/musicindex.rb
CHANGED
@@ -10,14 +10,6 @@ module Rack
|
|
10
10
|
|
11
11
|
def init(options)
|
12
12
|
@dirs = options
|
13
|
-
@files = {}
|
14
|
-
@static_paths = {}
|
15
|
-
@dirs.each do |path, dir|
|
16
|
-
@files[path] = Dir[dir + '/*.mp3']
|
17
|
-
@files[path].each do |filename|
|
18
|
-
@static_paths[path + '/' + ::File.basename(filename)] = filename
|
19
|
-
end
|
20
|
-
end
|
21
13
|
end
|
22
14
|
|
23
15
|
def call(env)
|
@@ -25,6 +17,8 @@ module Rack
|
|
25
17
|
|
26
18
|
path_info = env['PATH_INFO']
|
27
19
|
|
20
|
+
update_files
|
21
|
+
|
28
22
|
if dirs[path_info]
|
29
23
|
headers['Content-Type'] = 'application/xml;charset=utf-8'
|
30
24
|
body = podcast(env)
|
@@ -56,6 +50,18 @@ module Rack
|
|
56
50
|
@static_paths
|
57
51
|
end
|
58
52
|
|
53
|
+
def update_files
|
54
|
+
@files = {}
|
55
|
+
@static_paths = {}
|
56
|
+
|
57
|
+
dirs.each do |path, dir|
|
58
|
+
@files[path] = Dir[dir + '/*.mp3']
|
59
|
+
@files[path].each do |filename|
|
60
|
+
@static_paths[path + '/' + ::File.basename(filename)] = filename
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
59
65
|
def podcast(env)
|
60
66
|
path = env['PATH_INFO']
|
61
67
|
req = Rack::Request.new(env)
|
@@ -4,12 +4,23 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_app')
|
|
4
4
|
set :environment, :test
|
5
5
|
|
6
6
|
require 'nokogiri'
|
7
|
+
require 'fileutils'
|
7
8
|
|
8
9
|
describe Rack::MusicIndex do
|
9
10
|
def app
|
10
11
|
Sinatra::Application
|
11
12
|
end
|
12
13
|
|
14
|
+
before do
|
15
|
+
@mp3 = fixture('/foo/test2.mp3')
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
if File.exist?(@mp3)
|
20
|
+
FileUtils.rm(@mp3)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
13
24
|
it 'should index mp3s as podcast' do
|
14
25
|
get '/foo'
|
15
26
|
|
@@ -31,11 +42,34 @@ describe Rack::MusicIndex do
|
|
31
42
|
item.xpath('enclosure')[0]['url'].should eql('http://example.org/foo/test.mp3')
|
32
43
|
end
|
33
44
|
|
45
|
+
it 'should reflect file changes without restart' do
|
46
|
+
get '/foo'
|
47
|
+
|
48
|
+
xml = Nokogiri::XML(last_response.body)
|
49
|
+
xml.xpath('//item').size.should eql(1)
|
50
|
+
|
51
|
+
open(@mp3, 'w') do |f|
|
52
|
+
f.write('xxx')
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/foo'
|
56
|
+
|
57
|
+
xml = Nokogiri::XML(last_response.body)
|
58
|
+
xml.xpath('//item').size.should eql(2)
|
59
|
+
|
60
|
+
FileUtils.rm(@mp3)
|
61
|
+
|
62
|
+
get '/foo'
|
63
|
+
|
64
|
+
xml = Nokogiri::XML(last_response.body)
|
65
|
+
xml.xpath('//item').size.should eql(1)
|
66
|
+
end
|
67
|
+
|
34
68
|
it 'should return mp3' do
|
35
69
|
get '/foo/test.mp3'
|
36
70
|
|
37
71
|
last_response.should be_ok
|
38
72
|
last_response['Content-Type'].should eql('audio/mpeg')
|
39
|
-
last_response.body.should eql(open(fixture('/foo/test.mp3')).read)
|
73
|
+
last_response.body.should eql(open(fixture('/foo/test.mp3'), 'rb').read)
|
40
74
|
end
|
41
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-musicindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-06-
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
segments:
|
144
144
|
- 0
|
145
|
-
hash:
|
145
|
+
hash: 1861601957607199422
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
none: false
|
148
148
|
requirements:
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: '0'
|
152
152
|
segments:
|
153
153
|
- 0
|
154
|
-
hash:
|
154
|
+
hash: 1861601957607199422
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
157
|
rubygems_version: 1.8.24
|