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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38efb585c476f6e9486d2c1f81f4a0fc05f96d33
4
- data.tar.gz: 00542d977dd68357eb3e8e8288373d774821c022
3
+ metadata.gz: dc0e379580b19b209e120d6c43ee915d47137084
4
+ data.tar.gz: a0bafbd3f9535780c508dcaa1b98cd259a37417d
5
5
  SHA512:
6
- metadata.gz: 6f96564319f5ddd6eefc31541a3d0f0139fc44534b24fffb47d15407b29380c858fc124dec26fb6a452c3b22a95351a4f78a0dc1ae25848ac5961252529c2ed7
7
- data.tar.gz: e201d72434d0828eb1d7a43b65f29ecfbc021f40be6512a87b1726be21427a41fb787ffaf9e171c9e7e4643f2702cb23dbe6030f8679ee680d7b590e01851ac8
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
- ```sh
35
+ ```shell
36
36
  $ aric --list
37
37
  ```
38
38
 
39
39
  Execute jobs as follow.
40
40
 
41
- ```sh
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
- ```sh
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
- ## Development
72
+ ### Use As Library
73
+
74
+ ```rb
75
+ require 'aric/resource/track'
76
76
 
77
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
77
+ tracks = Track.find_by(name: 'Puppy Love')
78
+ track = tracks.first
78
79
 
79
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 JobHandler.jobs
16
+ puts job_list
16
17
  when play?
17
- JobHandler.play(*@args)
18
+ play
18
19
  else
19
- puts JobHandler.new(job).run(*values)
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
@@ -0,0 +1,13 @@
1
+ module Aric
2
+ module Error
3
+ class JobNotFound < StandardError
4
+ def initialize(job)
5
+ @job = job
6
+ end
7
+
8
+ def to_s
9
+ "Unkonw job specified `#{@job}`"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Aric
2
+ module Error
3
+ class JobNameRequired < StandardError
4
+ def to_s
5
+ 'Job name required, But not pass job name'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Aric
2
+ module Error
3
+ class ScriptExecutionError < StandardError
4
+ def initialize(cmd, message)
5
+ @cmd = cmd
6
+ @message = message
7
+ end
8
+
9
+ def to_s
10
+ "#{@message} in #{cmd}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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
- if args.first && jobs.include?(args.first.to_sym)
10
- new(:play_music).run(*args)
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
- raise JobNotFound
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
 
@@ -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("osascript -l JavaScript #{script_file_path} #{args}")
18
- raise "#{stderr} at osascript -l JavaScript #{script_file_path} #{args}" unless status.success?
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
@@ -1,3 +1,3 @@
1
1
  module Aric
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
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.0
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-19 00:00:00.000000000 Z
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
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here