playa 0.0.14 → 0.0.15

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: dc0a02dbfb9185a17e8be2af35a219bea29784b6
4
- data.tar.gz: b2488157606b4f9bfe0e6c278c57170c272f6e2d
3
+ metadata.gz: 98e4eebc7b7b839e9a080ae94491ba195a7c363a
4
+ data.tar.gz: 39f1f5bd6ba46abd7e0c4d8b8ac9c102b25f6413
5
5
  SHA512:
6
- metadata.gz: ce6f77dfa8a56a5f848489b44559fbacc87f966c6ac86a1a0a6024352003f2718f43eb827f6c39537c7a22a9b789f69592c4c252f212030dff2e0b75adc2be3c
7
- data.tar.gz: e83fcad9c273cc8370be158d1f1d9ba25c59672f46b5823de19fa8b1817c074c37b8f9cc6d61ee8a53007fca6e1282f5429b209d771429ece060b1f17871c8d7
6
+ metadata.gz: 248d5850978f2c01d0f0276509f7fd97628d45f3c615294f1cd58075134e9798751baf740f00433eaf8bcc31ce697e9bf4875ad05f860b9f3a7c3fa4fc22bbcb
7
+ data.tar.gz: 319d313404f3947c7133abf8924e0d1cf85e5acb22d468fb135a237ac9c45549248958a392bc9b34e8f8b559316a4b444f51f94efb4c17a9899c7b6e74b59830
data/lib/playa.rb CHANGED
@@ -6,6 +6,7 @@ require 'audite'
6
6
  require 'mp3info'
7
7
  require 'vedeu'
8
8
 
9
+ require 'playa/log'
9
10
  require 'playa/models/track'
10
11
  require 'playa/models/track_collection'
11
12
  require 'playa/models/player'
@@ -1,4 +1,8 @@
1
1
  module Playa
2
+ def self.log(message)
3
+ Playa::Log.logger.debug(message)
4
+ end
5
+
2
6
  class Application
3
7
  include Vedeu
4
8
 
@@ -2,98 +2,92 @@ module Playa
2
2
  class Controller
3
3
  include Vedeu
4
4
 
5
- def initialize(args = [])
6
- @player = Player.new
5
+ event :complete do
6
+ trigger(:_menu_next_, 'playlist')
7
+ trigger(:_menu_select_, 'playlist')
8
+ trigger(:select, trigger(:_menu_selected_, 'playlist'))
9
+ trigger(:update)
10
+ end
11
+
12
+ event :_initialize_ do
13
+ trigger(:show_startup)
14
+ end
15
+
16
+ event :key do |key|
17
+ case key
18
+ when :left, 'h' then trigger(:rewind)
19
+ when :right, 'l' then trigger(:forward)
20
+ when ' ' then trigger(:toggle)
21
+ when :up, 'k' then
22
+ trigger(:_menu_prev_, 'playlist')
23
+ trigger(:update)
24
+
25
+ when :down, 'j' then
26
+ trigger(:_menu_next_, 'playlist')
27
+ trigger(:update)
28
+
29
+ when '?' then trigger(:show_help)
30
+ when 'p', 's' then trigger(:show_player)
31
+ when 'q' then trigger(:_exit_)
32
+ when :enter then
33
+ trigger(:_menu_select_, 'playlist')
34
+ trigger(:select, trigger(:_menu_selected_, 'playlist'))
35
+ trigger(:update)
7
36
 
8
- event :_initialize_ do
9
- trigger(:show_startup)
10
37
  end
38
+ end
39
+
40
+ event :select do |track|
41
+ trigger(:play, track)
42
+ end
43
+
44
+ event :update do
45
+ PlaylistView.render
46
+ trigger(:_refresh_playlist_)
47
+ end
48
+
49
+ def initialize(args = [])
50
+ @args = args
51
+
52
+ @player = Player.new
53
+ @player.events.on(:position_change) { trigger(:progress_update) }
54
+ @player.events.on(:complete) { trigger(:complete) }
11
55
 
12
56
  event :show_startup do
13
57
  trigger(:_clear_)
14
-
15
58
  StartupView.render
16
-
17
59
  trigger(:_refresh_group_player_)
18
60
  end
19
61
 
20
62
  event :show_help do
21
63
  trigger(:_clear_)
22
-
23
64
  HelpView.render
24
-
25
65
  trigger(:_refresh_help_)
26
66
  end
27
67
 
28
68
  event :show_player do
29
69
  trigger(:_clear_)
30
-
31
- PlaylistView.render(menu)
70
+ PlaylistView.render
32
71
  StatusView.render
33
72
  ProgressView.render(@player)
34
-
35
73
  trigger(:_refresh_group_player_)
36
74
  end
37
75
 
38
- event :update do
39
- PlaylistView.render(menu)
40
- trigger(:_refresh_playlist_)
41
- end
42
-
43
- event :progress_update, 0.5 do
76
+ event(:progress_update, { delay: 0.5 }) do
44
77
  ProgressView.render(@player)
45
78
  trigger(:_refresh_progress_)
46
79
  end
47
80
 
48
- event :select do |track|
49
- trigger(:play, track)
50
- end
51
-
52
- event :complete do
53
- trigger(:menu_next)
54
- trigger(:menu_select)
55
- trigger(:select, menu.current_item)
56
- trigger(:update)
57
- end
58
-
59
- event :key do |key|
60
- case key
61
- when :left, 'h' then trigger(:rewind)
62
- when :right, 'l' then trigger(:forward)
63
- when ' ' then trigger(:toggle)
64
- when :up, 'k' then
65
- trigger(:menu_prev)
66
- trigger(:update)
67
- when :down, 'j' then
68
- trigger(:menu_next)
69
- trigger(:update)
70
- when '?' then trigger(:show_help)
71
- when 'p', 's' then trigger(:show_player)
72
- when 'q' then trigger(:_exit_)
73
- when :enter
74
- trigger(:menu_select)
75
- trigger(:select, menu.current_item)
76
- trigger(:update)
77
- end
78
- end
79
-
80
- @player.events.on(:position_change) { trigger(:progress_update) }
81
- @player.events.on(:complete) { trigger(:complete) }
82
-
83
- @args = args
84
- trigger(:show_startup)
81
+ menu('playlist') { items(tracks) }
85
82
  end
86
83
 
87
84
  private
88
85
 
89
86
  attr_reader :args
90
87
 
91
- def menu
92
- @_menu ||= Vedeu::Menu.new(tracks)
93
- end
94
-
95
88
  def tracks
96
- @_tracks ||= TrackCollection.new(args).tracks
89
+ @tracks ||= TrackCollection.new(args).tracks
97
90
  end
91
+
98
92
  end
99
93
  end
data/lib/playa/log.rb ADDED
@@ -0,0 +1,114 @@
1
+ require 'fileutils'
2
+ require 'logger'
3
+ require 'time'
4
+
5
+ module Playa
6
+ # :nocov:
7
+ class MonoLogger < Logger
8
+ # Create a trappable Logger instance.
9
+ #
10
+ # @param logdev [String|IO] The filename (String) or IO object (typically
11
+ # STDOUT, STDERR or an open file).
12
+ # @param shift_age [] Number of old log files to keep, or frequency of
13
+ # rotation (daily, weekly, monthly).
14
+ # @param shift_size [] Maximum log file size (only applies when shift_age
15
+ # is a number).
16
+ #
17
+ # @example
18
+ # Logger.new(name, shift_age = 7, shift_size = 1048576)
19
+ # Logger.new(name, shift_age = 'weekly')
20
+ #
21
+ def initialize(logdev, shift_age=nil, shift_size=nil)
22
+ @progname = nil
23
+ @level = DEBUG
24
+ @default_formatter = Formatter.new
25
+ @formatter = nil
26
+ @logdev = nil
27
+ if logdev
28
+ @logdev = LocklessLogDevice.new(logdev)
29
+ end
30
+ end
31
+
32
+ class LocklessLogDevice < LogDevice
33
+ def initialize(log = nil)
34
+ @dev = @filename = @shift_age = @shift_size = nil
35
+ if log.respond_to?(:write) and log.respond_to?(:close)
36
+ @dev = log
37
+ else
38
+ @dev = open_logfile(log)
39
+ @dev.sync = true
40
+ @filename = log
41
+ end
42
+ end
43
+
44
+ def write(message)
45
+ @dev.write(message)
46
+ rescue Exception => ignored
47
+ warn("log writing failed. #{ignored}")
48
+ end
49
+
50
+ def close
51
+ @dev.close rescue nil
52
+ end
53
+
54
+ private
55
+
56
+ def open_logfile(filename)
57
+ if (FileTest.exist?(filename))
58
+ open(filename, (File::WRONLY | File::APPEND))
59
+ else
60
+ create_logfile(filename)
61
+ end
62
+ end
63
+
64
+ def create_logfile(filename)
65
+ logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
66
+ logdev.sync = true
67
+ add_log_header(logdev)
68
+ logdev
69
+ end
70
+
71
+ def add_log_header(file)
72
+ file.write(
73
+ "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
74
+ )
75
+ end
76
+ end
77
+ end
78
+
79
+ class Log
80
+
81
+ # @return [TrueClass]
82
+ def self.logger
83
+ @logger ||= MonoLogger.new(filename).tap do |log|
84
+ log.formatter = proc do |_, time, _, message|
85
+ time.utc.iso8601 + ": " + message + "\n"
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+
92
+ # @api private
93
+ # @return [String]
94
+ def self.filename
95
+ @_filename ||= directory + '/playa.log'
96
+ end
97
+
98
+ # @api private
99
+ # @return [String]
100
+ def self.directory
101
+ FileUtils.mkdir_p(path) unless File.directory?(path)
102
+
103
+ path
104
+ end
105
+
106
+ # @api private
107
+ # @return [String]
108
+ def self.path
109
+ Dir.home + '/.playa'
110
+ end
111
+
112
+ end
113
+ # :nocov:
114
+ end
@@ -4,7 +4,7 @@ module Playa
4
4
 
5
5
  def render
6
6
  view 'playlist' do
7
- self.object.view.each do |sel, cur, item|
7
+ playlist_menu.each do |sel, cur, item|
8
8
  if sel && cur
9
9
  line do
10
10
  stream do
@@ -84,5 +84,9 @@ module Playa
84
84
  Vedeu.use('playlist').viewport_width
85
85
  end
86
86
 
87
+ def playlist_menu
88
+ @playlist_menu = Vedeu.trigger(:_menu_view_, 'playlist')
89
+ end
90
+
87
91
  end
88
92
  end
data/playa.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'playa'
7
- spec.version = '0.0.14'
7
+ spec.version = '0.0.15'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = 'Plays mp3s from a directory.'
@@ -19,15 +19,15 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency 'bundler', '~> 1.6'
21
21
  spec.add_development_dependency 'guard', '2.6.1'
22
- spec.add_development_dependency 'guard-minitest', '2.3.1'
23
- spec.add_development_dependency 'minitest', '5.4.0'
22
+ spec.add_development_dependency 'guard-minitest', '2.3.2'
23
+ spec.add_development_dependency 'minitest', '5.4.1'
24
24
  spec.add_development_dependency 'minitest-reporters', '1.0.5'
25
25
  spec.add_development_dependency 'mocha', '1.1.0'
26
- spec.add_development_dependency 'pry', '0.10.0'
26
+ spec.add_development_dependency 'pry', '0.10.1'
27
27
  spec.add_development_dependency 'rake', '10.3.2'
28
28
  spec.add_development_dependency 'simplecov', '0.9.0'
29
29
 
30
30
  spec.add_dependency 'audite', '0.3.0'
31
31
  spec.add_dependency 'ruby-mp3info', '0.8.4'
32
- spec.add_dependency 'vedeu', '0.1.17'
32
+ spec.add_dependency 'vedeu', '0.2.0'
33
33
  end
@@ -18,14 +18,19 @@ module Playa
18
18
  text: "Help!"
19
19
  }
20
20
  ],
21
- style: []
21
+ style: [],
22
+ parent: {
23
+ colour: {},
24
+ style: ''
25
+ }
22
26
  }
23
27
  ],
24
28
  colour: {},
25
29
  style: "",
26
30
  geometry: {},
27
31
  cursor: true,
28
- delay: 0.0
32
+ delay: 0.0,
33
+ parent: {}
29
34
  }
30
35
  ]
31
36
  }
@@ -22,17 +22,26 @@ module Playa
22
22
  style: [],
23
23
  text: " ",
24
24
  width: 60,
25
- align: :left
25
+ align: :left,
26
+ parent: {
27
+ colour: {},
28
+ style: []
29
+ }
26
30
  }
27
31
  ],
28
- style: []
32
+ style: [],
33
+ parent: {
34
+ colour: {},
35
+ style: ''
36
+ }
29
37
  }
30
38
  ],
31
39
  colour: {},
32
40
  style: "",
33
41
  geometry: {},
34
42
  cursor: true,
35
- delay: 0.0
43
+ delay: 0.0,
44
+ parent: {}
36
45
  }
37
46
  ]
38
47
  }
@@ -18,14 +18,19 @@ module Playa
18
18
  text: "Welcome to Playa."
19
19
  }
20
20
  ],
21
- style: []
21
+ style: [],
22
+ parent: {
23
+ colour: {},
24
+ style: ''
25
+ }
22
26
  }
23
27
  ],
24
28
  colour: {},
25
29
  style: "",
26
30
  geometry: {},
27
31
  cursor: true,
28
- delay: 0.0
32
+ delay: 0.0,
33
+ parent: {}
29
34
  }, {
30
35
  name: "playlist",
31
36
  group: "",
@@ -37,14 +42,19 @@ module Playa
37
42
  text: "An mp3 player in your console."
38
43
  }
39
44
  ],
40
- style: []
45
+ style: [],
46
+ parent: {
47
+ colour: {},
48
+ style: ''
49
+ }
41
50
  }
42
51
  ],
43
52
  colour: {},
44
53
  style: "",
45
54
  geometry: {},
46
55
  cursor: true,
47
- delay: 0.0
56
+ delay: 0.0,
57
+ parent: {}
48
58
  }, {
49
59
  name: "status",
50
60
  group: "",
@@ -56,14 +66,19 @@ module Playa
56
66
  text: "Press `s` to begin."
57
67
  }
58
68
  ],
59
- style: []
69
+ style: [],
70
+ parent: {
71
+ colour: {},
72
+ style: ''
73
+ }
60
74
  }
61
75
  ],
62
76
  colour: {},
63
77
  style: "",
64
78
  geometry: {},
65
79
  cursor: true,
66
- delay: 0.0
80
+ delay: 0.0,
81
+ parent: {}
67
82
  }
68
83
  ]
69
84
  }
@@ -21,7 +21,11 @@ module Playa
21
21
  style: [],
22
22
  text: " ▲",
23
23
  width: nil,
24
- align: :left
24
+ align: :left,
25
+ parent: {
26
+ colour: {},
27
+ style: []
28
+ }
25
29
  }, {
26
30
  colour: {
27
31
  foreground: "#ffffff"
@@ -29,7 +33,11 @@ module Playa
29
33
  style: [],
30
34
  text: " Prev ",
31
35
  width: nil,
32
- align: :left
36
+ align: :left,
37
+ parent: {
38
+ colour: {},
39
+ style: []
40
+ }
33
41
  }, {
34
42
  colour: {
35
43
  foreground: "#ff0000"
@@ -37,7 +45,11 @@ module Playa
37
45
  style: [],
38
46
  text: "▼",
39
47
  width: nil,
40
- align: :left
48
+ align: :left,
49
+ parent: {
50
+ colour: {},
51
+ style: []
52
+ }
41
53
  }, {
42
54
  colour: {
43
55
  foreground: "#ffffff"
@@ -45,7 +57,11 @@ module Playa
45
57
  style: [],
46
58
  text: " Next ",
47
59
  width: nil,
48
- align: :left
60
+ align: :left,
61
+ parent: {
62
+ colour: {},
63
+ style: []
64
+ }
49
65
  }, {
50
66
  colour: {
51
67
  foreground: "#ff0000"
@@ -53,7 +69,11 @@ module Playa
53
69
  style: [],
54
70
  text: "↲",
55
71
  width: nil,
56
- align: :left
72
+ align: :left,
73
+ parent: {
74
+ colour: {},
75
+ style: []
76
+ }
57
77
  }, {
58
78
  colour: {
59
79
  foreground: "#ffffff"
@@ -61,7 +81,11 @@ module Playa
61
81
  style: [],
62
82
  text: " Select ",
63
83
  width: nil,
64
- align: :left
84
+ align: :left,
85
+ parent: {
86
+ colour: {},
87
+ style: []
88
+ }
65
89
  }, {
66
90
  colour: {
67
91
  foreground: "#ff0000"
@@ -69,7 +93,11 @@ module Playa
69
93
  style: [],
70
94
  text: "⎕",
71
95
  width: nil,
72
- align: :left
96
+ align: :left,
97
+ parent: {
98
+ colour: {},
99
+ style: []
100
+ }
73
101
  }, {
74
102
  colour: {
75
103
  foreground: "#ffffff"
@@ -77,7 +105,11 @@ module Playa
77
105
  style: [],
78
106
  text: " Pause ",
79
107
  width: nil,
80
- align: :left
108
+ align: :left,
109
+ parent: {
110
+ colour: {},
111
+ style: []
112
+ }
81
113
  }, {
82
114
  colour: {
83
115
  foreground: "#ff0000"
@@ -85,7 +117,11 @@ module Playa
85
117
  style: [],
86
118
  text: "Q",
87
119
  width: nil,
88
- align: :left
120
+ align: :left,
121
+ parent: {
122
+ colour: {},
123
+ style: []
124
+ }
89
125
  }, {
90
126
  colour: {
91
127
  foreground: "#ffffff"
@@ -93,17 +129,26 @@ module Playa
93
129
  style: [],
94
130
  text: " Quit ",
95
131
  width: nil,
96
- align: :left
132
+ align: :left,
133
+ parent: {
134
+ colour: {},
135
+ style: []
136
+ }
97
137
  }
98
138
  ],
99
- style: []
139
+ style: [],
140
+ parent: {
141
+ colour: {},
142
+ style: ''
143
+ }
100
144
  }
101
145
  ],
102
146
  colour: {},
103
147
  style: "",
104
148
  geometry: {},
105
149
  cursor: true,
106
- delay: 0.0
150
+ delay: 0.0,
151
+ parent: {}
107
152
  }
108
153
  ]
109
154
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.3.1
47
+ version: 2.3.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.3.1
54
+ version: 2.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 5.4.0
61
+ version: 5.4.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 5.4.0
68
+ version: 5.4.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-reporters
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.10.0
103
+ version: 0.10.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.10.0
110
+ version: 0.10.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 0.1.17
173
+ version: 0.2.0
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 0.1.17
180
+ version: 0.2.0
181
181
  description: An example app using Vedeu.
182
182
  email:
183
183
  - gavinlaking@gmail.com
@@ -198,6 +198,7 @@ files:
198
198
  - lib/playa/application.rb
199
199
  - lib/playa/controllers/controller.rb
200
200
  - lib/playa/helpers/helpers.rb
201
+ - lib/playa/log.rb
201
202
  - lib/playa/models/player.rb
202
203
  - lib/playa/models/track.rb
203
204
  - lib/playa/models/track_collection.rb