aric 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -9
- data/lib/aric/command.rb +21 -7
- data/lib/aric/error/job_name_required.rb +13 -0
- data/lib/aric/error/job_not_found.rb +9 -0
- data/lib/aric/error/script_execution_error.rb +14 -0
- data/lib/aric/job_handler.rb +14 -6
- data/lib/aric/script_runner.rb +8 -3
- data/lib/aric/version.rb +1 -1
- metadata +5 -4
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc0e379580b19b209e120d6c43ee915d47137084
|
4
|
+
data.tar.gz: a0bafbd3f9535780c508dcaa1b98cd259a37417d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae7a5f63aa1746a0d2fde61fd9fc4f14387672f4368a159020d9c557555ad69e62f235aae7ff1bbff9b86efbc61892728efb681685355acadb6921bfb4442d8
|
7
|
+
data.tar.gz: 91659c9b23d3a65605bd94eef6027e3ea03e5f261e2410f821990e7a3c69d20dbcd1595559a66f8d2e44003259a20956a599f922516985593839d92fd76602b3
|
data/README.md
CHANGED
@@ -32,13 +32,13 @@ Or install it yourself as:
|
|
32
32
|
|
33
33
|
Show avalable jobs.
|
34
34
|
|
35
|
-
```
|
35
|
+
```shell
|
36
36
|
$ aric --list
|
37
37
|
```
|
38
38
|
|
39
39
|
Execute jobs as follow.
|
40
40
|
|
41
|
-
```
|
41
|
+
```shell
|
42
42
|
// play trakcs
|
43
43
|
$ aric play
|
44
44
|
|
@@ -48,9 +48,6 @@ $ aric next
|
|
48
48
|
// volume up by 10
|
49
49
|
$ aric up 10
|
50
50
|
|
51
|
-
// volume up by 10
|
52
|
-
$ aric up 10
|
53
|
-
|
54
51
|
// show tracks in current playlists
|
55
52
|
$ aric current_playlist_tracks
|
56
53
|
|
@@ -63,7 +60,7 @@ $ aric activate
|
|
63
60
|
|
64
61
|
Play founded tracks with `-p` option.
|
65
62
|
|
66
|
-
```
|
63
|
+
```shell
|
67
64
|
// play loved tracks
|
68
65
|
$ aric -p find_loved_tracks
|
69
66
|
|
@@ -72,11 +69,23 @@ $ aric -p find_loved_tracks
|
|
72
69
|
$ aric -p find_tracks <track_name>
|
73
70
|
```
|
74
71
|
|
75
|
-
|
72
|
+
### Use As Library
|
73
|
+
|
74
|
+
```rb
|
75
|
+
require 'aric/resource/track'
|
76
76
|
|
77
|
-
|
77
|
+
tracks = Track.find_by(name: 'Puppy Love')
|
78
|
+
track = tracks.first
|
78
79
|
|
79
|
-
|
80
|
+
puts track.name
|
81
|
+
|
82
|
+
track.play
|
83
|
+
track.stop
|
84
|
+
|
85
|
+
require 'aric/job/volume'
|
86
|
+
Volume.up 10
|
87
|
+
Volume.down 10
|
88
|
+
```
|
80
89
|
|
81
90
|
## Contributing
|
82
91
|
|
data/lib/aric/command.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
require 'aric/job_handler'
|
3
|
+
require 'aric/error/job_name_required'
|
4
|
+
require 'aric/error/job_not_found'
|
5
|
+
require 'aric/error/script_execution_error'
|
3
6
|
|
4
7
|
module Aric
|
5
8
|
class Command
|
6
|
-
class JobNameRequired < StandardError; end
|
7
|
-
|
8
9
|
def initialize(args = ARGV)
|
9
10
|
@args = args
|
10
11
|
end
|
@@ -12,12 +13,14 @@ module Aric
|
|
12
13
|
def call
|
13
14
|
case
|
14
15
|
when list?
|
15
|
-
puts
|
16
|
+
puts job_list
|
16
17
|
when play?
|
17
|
-
|
18
|
+
play
|
18
19
|
else
|
19
|
-
puts
|
20
|
+
puts run
|
20
21
|
end
|
22
|
+
rescue Aric::Error::JobNameRequired, Aric::Error::JobNotFound, Aric::Error::ScriptExecutionError => e
|
23
|
+
puts "Error: #{e}"
|
21
24
|
end
|
22
25
|
|
23
26
|
private
|
@@ -27,7 +30,19 @@ module Aric
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def job
|
30
|
-
@args.first or raise JobNameRequired
|
33
|
+
@args.first or raise Aric::Error::JobNameRequired
|
34
|
+
end
|
35
|
+
|
36
|
+
def run
|
37
|
+
JobHandler.new(job).run(*values)
|
38
|
+
end
|
39
|
+
|
40
|
+
def play
|
41
|
+
JobHandler.play(*@args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def job_list
|
45
|
+
JobHandler.jobs
|
31
46
|
end
|
32
47
|
|
33
48
|
def list?
|
@@ -50,7 +65,6 @@ module Aric
|
|
50
65
|
opt.separator 'Options:'
|
51
66
|
opt.on('-l', '--list', 'show available methods')
|
52
67
|
opt.on('-p', '--play', 'play found tracks')
|
53
|
-
# opt.on('-d', 'demonize')
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
data/lib/aric/job_handler.rb
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
require 'aric/job'
|
2
|
+
require 'aric/error/job_name_required'
|
3
|
+
require 'aric/error/job_not_found'
|
2
4
|
|
3
5
|
module Aric
|
4
6
|
class JobHandler
|
5
|
-
class JobNotFound < StandardError; end
|
6
|
-
|
7
7
|
class << self
|
8
8
|
def play(*args)
|
9
|
-
|
10
|
-
|
9
|
+
case
|
10
|
+
when !args.first
|
11
|
+
raise Aric::Error::JobNameRequired.new
|
12
|
+
when !jobs.include?(args.first.to_sym)
|
13
|
+
raise Aric::Error::JobNotFound.new(args.first)
|
11
14
|
else
|
12
|
-
|
15
|
+
new(:play_music).run(*args)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
19
|
+
# Avalable jobs names
|
20
|
+
# @return [Array<Symbol>]
|
16
21
|
def jobs
|
17
22
|
@jobs ||= job_class_hash.values.flat_map(&:itself)
|
18
23
|
end
|
19
24
|
|
25
|
+
# Avalable jobs names and Class that them contain
|
26
|
+
# @return [Hash<Class, Symbol>]
|
20
27
|
def job_class_hash
|
21
28
|
@job_class_hash ||= job_classes.each_with_object({}) do |c, a|
|
22
29
|
a[c] = c.public_instance_methods(false)
|
@@ -25,6 +32,8 @@ module Aric
|
|
25
32
|
|
26
33
|
private
|
27
34
|
|
35
|
+
# Classes that contain avalable jobs
|
36
|
+
# @return [Job::Base] Job::Base extended class
|
28
37
|
def job_classes
|
29
38
|
@job_class ||= Job.constants.map { |e| Job.const_get(e) }
|
30
39
|
end
|
@@ -35,7 +44,6 @@ module Aric
|
|
35
44
|
end
|
36
45
|
|
37
46
|
def run(*args)
|
38
|
-
# Check argument number
|
39
47
|
job_class.run(@job_name, *args)
|
40
48
|
end
|
41
49
|
|
data/lib/aric/script_runner.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'aric/error/script_execution_error'
|
2
3
|
|
3
4
|
module Aric
|
4
5
|
class ScriptRunner
|
@@ -13,14 +14,18 @@ module Aric
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def run(args = [])
|
16
|
-
args = Array(args).join(' ')
|
17
|
-
stdout, stderr, status = Open3.capture3(
|
18
|
-
raise
|
17
|
+
@args = Array(args).join(' ')
|
18
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
19
|
+
raise Arci::Error::ScriptExecutionError.new(stderr, cmd) unless status.success?
|
19
20
|
stdout.strip
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
25
|
+
def cmd
|
26
|
+
@cmd ||= "osascript -l JavaScript #{script_file_path} #{@args}"
|
27
|
+
end
|
28
|
+
|
24
29
|
def script_file_path
|
25
30
|
"#{script_base_dir}/#{@file_name}.js"
|
26
31
|
end
|
data/lib/aric/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ganmacs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -72,7 +72,6 @@ email:
|
|
72
72
|
executables:
|
73
73
|
- aric
|
74
74
|
- console
|
75
|
-
- setup
|
76
75
|
extensions: []
|
77
76
|
extra_rdoc_files: []
|
78
77
|
files:
|
@@ -86,9 +85,11 @@ files:
|
|
86
85
|
- aric.gemspec
|
87
86
|
- bin/aric
|
88
87
|
- bin/console
|
89
|
-
- bin/setup
|
90
88
|
- lib/aric.rb
|
91
89
|
- lib/aric/command.rb
|
90
|
+
- lib/aric/error/job_name_required.rb
|
91
|
+
- lib/aric/error/job_not_found.rb
|
92
|
+
- lib/aric/error/script_execution_error.rb
|
92
93
|
- lib/aric/job.rb
|
93
94
|
- lib/aric/job/base.rb
|
94
95
|
- lib/aric/job/finder.rb
|