shelr 0.12.2 → 0.12.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/Rakefile +6 -0
- data/lib/shelr/publisher.rb +12 -0
- data/lib/shelr/recorder.rb +24 -14
- data/lib/shelr/version.rb +1 -1
- data/spec/shelr/publisher_spec.rb +9 -1
- data/spec/shelr/recorder_spec.rb +7 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -6,4 +6,10 @@ require 'rspec/core/rake_task'
|
|
6
6
|
desc 'Run all specs in spec directory'
|
7
7
|
RSpec::Core::RakeTask.new
|
8
8
|
|
9
|
+
task :merge do
|
10
|
+
File.open('shelr', 'a+') { |f| f.puts "#/usr/bin/env ruby" }
|
11
|
+
`cat lib/shelr.rb lib/shelr/* bin/shelr | grep -v autoload >> shelr`
|
12
|
+
`chmod +x ./shelr`
|
13
|
+
end
|
14
|
+
|
9
15
|
task :default => :spec
|
data/lib/shelr/publisher.rb
CHANGED
@@ -5,6 +5,7 @@ module Shelr
|
|
5
5
|
class Publisher
|
6
6
|
|
7
7
|
def publish(id)
|
8
|
+
ensure_unlocked(id)
|
8
9
|
with_exception_handler do
|
9
10
|
uri = URI.parse(Shelr::API_URL + '/records')
|
10
11
|
params = { 'record' => prepare(id) }
|
@@ -24,6 +25,17 @@ module Shelr
|
|
24
25
|
|
25
26
|
private
|
26
27
|
|
28
|
+
def ensure_unlocked(id)
|
29
|
+
lock_path = File.join(Shelr.data_dir(id), 'lock')
|
30
|
+
if File.exist?(lock_path)
|
31
|
+
puts "=> Cannot publish"
|
32
|
+
puts "=> Record locked on #{File.read(lock_path)}"
|
33
|
+
puts "=> Esure no other shelr process running"
|
34
|
+
puts "=> Or remove lock file manually: #{lock_path}"
|
35
|
+
exit 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
27
39
|
def with_exception_handler(&block)
|
28
40
|
yield
|
29
41
|
rescue => e
|
data/lib/shelr/recorder.rb
CHANGED
@@ -14,20 +14,21 @@ module Shelr
|
|
14
14
|
|
15
15
|
def record!
|
16
16
|
check_record_dir
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
with_lock_file do
|
18
|
+
init_terminal
|
19
|
+
request_metadata
|
20
|
+
STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
|
21
|
+
STDOUT.puts "=> Your session started"
|
22
|
+
STDOUT.puts "=> Please, do not resize your terminal while recording"
|
23
|
+
STDOUT.puts "=> Press Ctrl+D or 'exit' to finish recording"
|
24
|
+
system(recorder_cmd)
|
25
|
+
save_as_typescript if Shelr.backend == 'ttyrec'
|
26
|
+
STDOUT.puts "-=" * (Shelr.terminal.size[:width] / 2)
|
27
|
+
STDOUT.puts "=> Session finished"
|
28
|
+
STDOUT.puts
|
29
|
+
STDOUT.puts "Replay : #{Shelr::APP_NAME} play last"
|
30
|
+
STDOUT.puts "Publish : #{Shelr::APP_NAME} push last"
|
31
|
+
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def request_metadata
|
@@ -44,6 +45,15 @@ module Shelr
|
|
44
45
|
|
45
46
|
private
|
46
47
|
|
48
|
+
def with_lock_file
|
49
|
+
lock_path = record_file('lock')
|
50
|
+
File.open(lock_path, 'w') do |f|
|
51
|
+
f.puts Time.now.to_s
|
52
|
+
end
|
53
|
+
yield
|
54
|
+
FileUtils.rm(lock_path)
|
55
|
+
end
|
56
|
+
|
47
57
|
def save_as_typescript
|
48
58
|
puts '=> Converting ttyrec -> typescript'
|
49
59
|
|
data/lib/shelr/version.rb
CHANGED
@@ -9,12 +9,20 @@ describe Shelr::Publisher do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#publish(id)" do
|
12
|
-
|
12
|
+
before do
|
13
13
|
STDIN.stub(:gets).and_return('something')
|
14
14
|
subject.stub(:handle_response)
|
15
15
|
subject.stub(:prepare).and_return(Fixture::load('record1.json'))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "prepares record as json" do
|
16
19
|
subject.should_receive(:prepare).with('hello')
|
20
|
+
subject.publish('hello')
|
21
|
+
end
|
17
22
|
|
23
|
+
it "it checks that file is not locked" do
|
24
|
+
subject.stub(:ensure_unlocked)
|
25
|
+
subject.should_receive(:ensure_unlocked).with('hello')
|
18
26
|
subject.publish('hello')
|
19
27
|
end
|
20
28
|
end
|
data/spec/shelr/recorder_spec.rb
CHANGED
@@ -12,12 +12,19 @@ describe Shelr::Recorder do
|
|
12
12
|
describe "#record!" do
|
13
13
|
before do
|
14
14
|
subject.stub(:system).with(anything).and_return(true)
|
15
|
+
subject.stub(:record_id => "1")
|
16
|
+
subject.stub(:with_lock_file).and_yield
|
15
17
|
end
|
16
18
|
|
17
19
|
it "starts script session" do
|
18
20
|
subject.should_receive(:system).with(/script/)
|
19
21
|
subject.record!
|
20
22
|
end
|
23
|
+
|
24
|
+
it "creates lock file" do
|
25
|
+
subject.should_receive(:with_lock_file)
|
26
|
+
subject.record!
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
describe "#request_metadata" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
segments:
|
88
88
|
- 0
|
89
|
-
hash:
|
89
|
+
hash: 1640227039729566954
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
none: false
|
92
92
|
requirements:
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
segments:
|
97
97
|
- 0
|
98
|
-
hash:
|
98
|
+
hash: 1640227039729566954
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
101
|
rubygems_version: 1.8.21
|