concerto_hardware 0.1 → 0.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78926444b14981b5a897bcbd8662f7d1abb5d2b6
|
4
|
+
data.tar.gz: 7e521966dae2d75ab103e62869eac6019100de01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f13bb763b161fa1cb5c10e662326d1a2261bc7e8369276d642ee9302850e2edb76dbd3ac908848a1b955851a45d37a5bd62f2d53b66da2e7a23330778f51414d
|
7
|
+
data.tar.gz: 115b314f996a2b566da9e0d91605abc70e93f9882f37956632a71a4681100bcffbbf1de3f642bd7a9b85fdea18aa77ca04bef493d94729579c307065124f5c16
|
@@ -42,7 +42,11 @@ class PlayersController < ApplicationController
|
|
42
42
|
|
43
43
|
respond_to do |format|
|
44
44
|
format.html # show.html.erb
|
45
|
-
format.json {
|
45
|
+
format.json {
|
46
|
+
render :json => @player.to_json(
|
47
|
+
:include => { :screen => { :only => :name } }
|
48
|
+
)
|
49
|
+
}
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
@@ -71,7 +75,7 @@ class PlayersController < ApplicationController
|
|
71
75
|
# POST /players
|
72
76
|
# POST /players.json
|
73
77
|
def create
|
74
|
-
@player = Player.new(
|
78
|
+
@player = Player.new(player_params)
|
75
79
|
auth!
|
76
80
|
|
77
81
|
respond_to do |format|
|
@@ -92,7 +96,7 @@ class PlayersController < ApplicationController
|
|
92
96
|
auth!
|
93
97
|
|
94
98
|
respond_to do |format|
|
95
|
-
if @player.update_attributes(
|
99
|
+
if @player.update_attributes(player_params)
|
96
100
|
format.html { redirect_to [hardware, @player], :notice => 'Player was successfully updated.' }
|
97
101
|
format.json { head :no_content }
|
98
102
|
else
|
@@ -114,6 +118,14 @@ class PlayersController < ApplicationController
|
|
114
118
|
format.json { head :no_content }
|
115
119
|
end
|
116
120
|
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
# Deal with strong parameter restrictions.
|
125
|
+
def player_params
|
126
|
+
params.require(:player).permit(:wkday_on_time, :wkday_off_time,
|
127
|
+
:wknd_on_time, :wkday_off_time, :wknd_disable, :force_off)
|
128
|
+
end
|
117
129
|
end
|
118
130
|
|
119
131
|
end
|
@@ -1,17 +1,18 @@
|
|
1
|
+
require 'concerto_hardware/time_accessible'
|
2
|
+
|
1
3
|
module ConcertoHardware
|
2
4
|
class Player < ActiveRecord::Base
|
3
|
-
|
5
|
+
# Get the time_accessor method for virtual Time attributes
|
6
|
+
extend ConcertoHardware::TimeAccessible
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
8
|
+
# Virtual attributes (these are read from and written to the database
|
9
|
+
# as parts of serialized JSON fields such as screen_on_off)
|
10
|
+
time_accessor :wkday_on_time, :wkday_off_time
|
11
|
+
time_accessor :wknd_on_time, :wknd_off_time
|
12
|
+
attr_accessor :wknd_disable
|
13
|
+
attr_accessor :force_off
|
14
|
+
|
15
|
+
belongs_to :screen
|
15
16
|
|
16
17
|
# Hack to get the multiparameter virtual attributes working
|
17
18
|
def self.create_time_zone_conversion_attribute?(name, column)
|
@@ -23,12 +24,6 @@ module ConcertoHardware
|
|
23
24
|
validates_presence_of :screen, :message => 'must exist'
|
24
25
|
validates_uniqueness_of :screen_id
|
25
26
|
|
26
|
-
time_accessor :wkday_on_time, :wkday_off_time
|
27
|
-
time_accessor :wknd_on_time, :wknd_off_time
|
28
|
-
time_accessor :party_time
|
29
|
-
attr_accessor :wknd_disable
|
30
|
-
attr_accessor :force_off
|
31
|
-
|
32
27
|
after_initialize :default_values
|
33
28
|
after_find :retrieve_screen_on_off
|
34
29
|
before_save :process_screen_on_off
|
@@ -169,7 +164,6 @@ module ConcertoHardware
|
|
169
164
|
return ConcertoConfig[:poll_interval].to_i
|
170
165
|
end
|
171
166
|
|
172
|
-
|
173
167
|
def as_json(options)
|
174
168
|
json = super(options)
|
175
169
|
json["screen_on_off"] = ActiveSupport::JSON.decode(self.screen_on_off)
|
data/config/routes.rb
CHANGED
@@ -13,9 +13,9 @@ ConcertoHardware::Engine.routes.draw do
|
|
13
13
|
resources :players do
|
14
14
|
collection do
|
15
15
|
# Look up a player based on the screen ID.
|
16
|
-
|
16
|
+
get 'by_screen/:screen_id' => ConcertoHardware::PlayersController.action(:show)
|
17
17
|
# Show the player associated with the logged in screen.
|
18
|
-
|
18
|
+
get 'current' => ConcertoHardware::PlayersController.action(:show)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ConcertoHardware
|
2
|
+
# Provides the time_accessor method, which is useful for creating a
|
3
|
+
# virtual parameter of type Time. The time is read and written as a
|
4
|
+
# standard Time-parasable string, which makes it possible to have form
|
5
|
+
# fields that reference the virtual attribute directly.
|
6
|
+
#
|
7
|
+
# Note that it is possible to set as a Time object (to save instantiations).
|
8
|
+
# You cannot read the Time object directly, however.
|
9
|
+
#
|
10
|
+
# Example
|
11
|
+
#
|
12
|
+
# class MyModel
|
13
|
+
# extend ConcertoHardware::TimeAccessible
|
14
|
+
# time_accessor :party_time
|
15
|
+
#
|
16
|
+
# def is_it_party_time?
|
17
|
+
# Time.now > Time.new(self.party_time || "9001")
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# inst = MyModel.new
|
22
|
+
# inst.party_time = "2011-11-11 11:11:11 -0000"
|
23
|
+
# inst.party_time # => "2011-11-11 11:11:11 -0000"
|
24
|
+
#
|
25
|
+
# inst.party_time = Time.now + 24*60*60 # the party is tommorrow
|
26
|
+
# inst.party_time # => "2014-10-01 23:01:06 -0400"
|
27
|
+
#
|
28
|
+
module TimeAccessible
|
29
|
+
def time_accessor(*syms)
|
30
|
+
syms.each do |sym|
|
31
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
32
|
+
def #{sym}
|
33
|
+
if @#{sym}_timeobj.is_a? Time
|
34
|
+
@#{sym}_timeobj.to_s
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def #{sym}=(val)
|
40
|
+
if val.is_a? Time
|
41
|
+
@#{sym}_timeobj = val
|
42
|
+
elsif val.is_a? String
|
43
|
+
@#{sym}_timeobj = Time.parse(val)
|
44
|
+
else
|
45
|
+
raise ArgumentError.new("Only Strings or Times allowed")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
RUBY
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end # TimeAccessible
|
52
|
+
end # ConcertoHardware
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concerto_hardware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Concerto Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- db/migrate/20121220000000_create_concerto_hardware_players.rb
|
56
56
|
- db/migrate/20131127201048_add_updates_to_concerto_hardware_players.rb
|
57
57
|
- lib/concerto_hardware/engine.rb
|
58
|
+
- lib/concerto_hardware/time_accessible.rb
|
58
59
|
- lib/concerto_hardware/version.rb
|
59
60
|
- lib/concerto_hardware.rb
|
60
61
|
- LICENSE
|