frecon 0.3.1 → 0.4.0

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: 57bd9b7c1164b8eb8fd9e832ac615281a0ae0921
4
- data.tar.gz: 3c24af5efdef6fc97d60148a7daceb0d8f61c4f8
3
+ metadata.gz: 53470115c1a7a01b3b7850dd9f803951bd3cb407
4
+ data.tar.gz: 820d7bc082d1bad50aac2aed9ea3c9b422fb8508
5
5
  SHA512:
6
- metadata.gz: 632ff7d628bfafa97051643b7553939598a84d3aacd84927d5393b5ec18e8b980ee00379204b0a6dd45ef7c1ef9628019d2f698511e1656b13c5c2ef5ec17c2c
7
- data.tar.gz: a39cf27d21e8747472bbfcfe98fd153e67473977f248baf65ab1723c587c52135a69ed1bf4070cce990978d50e4e6a0de6b7b6934d2398cfc4701a015da3f262
6
+ metadata.gz: edc0bebe5fbda796d7e4689db9cceff2eb4f91869e5ec38bf441eed9237ab51709cd065775cb6dd95d6729d8e28e87c55f20d46a03c2cec75a53e3fde86f8476
7
+ data.tar.gz: 82e6c63b5d4b6650bc85ba1119ea565c7b82f7c1c24acc7ba5eb00dde28d18fcc4eb1b6b25690e656c834fbc1e3f02adfd804a2a346bf3982000b6d243da661c
@@ -8,7 +8,7 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  module FReCon
11
- VERSION = "0.3.1"
11
+ VERSION = "0.4.0"
12
12
 
13
13
  @environment_variable = :development
14
14
 
@@ -15,23 +15,9 @@ module FReCon
15
15
  def self.start
16
16
  Database.setup(FReCon.environment)
17
17
 
18
- # Use pry if it is installed.
19
- # Use the context of the FReCon module;
20
- # this allows for writing "Team" instead of "FReCon::Team".
21
- begin
22
- require "pry"
18
+ require "pry"
23
19
 
24
- FReCon.pry
25
- rescue LoadError
26
- require "irb"
27
-
28
- IRB.setup nil
29
- IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
30
-
31
- require "irb/ext/multi-irb"
32
-
33
- IRB.irb nil, FReCon
34
- end
20
+ FReCon.pry
35
21
  end
36
22
  end
37
23
  end
@@ -26,7 +26,7 @@ module FReCon
26
26
  # Some models have to find themselves in special ways,
27
27
  # so this can be overridden with those ways.
28
28
  def self.find_model(params)
29
- model.find params[:id]
29
+ model.find params.delete("id")
30
30
  end
31
31
 
32
32
  # The 404 error message.
@@ -126,87 +126,16 @@ module FReCon
126
126
  end
127
127
 
128
128
  def self.index(params)
129
- params.delete("_")
130
-
131
- @models = params.empty? ? model.all : model.where(params)
132
-
133
- @models.to_json
134
- end
135
-
136
- def self.show_attribute(params, attribute)
137
- @model = find_model params
138
-
139
- if @model
140
- @model.send(attribute).to_json
129
+ if params.empty?
130
+ @models = model.all
141
131
  else
142
- raise RequestError.new(404, could_not_find(params[:id]), {params: params, attribute: attribute})
143
- end
144
- end
145
-
146
- def self.team_number_to_team_id(post_data)
147
- return post_data unless post_data.is_a?(Hash)
148
-
149
- if post_data["team_number"] && !post_data["team_id"]
150
- unless (team = Team.number post_data["team_number"]).nil?
151
- post_data["team_id"] = team.id
132
+ params.delete("splat")
133
+ params.delete("captures")
152
134
 
153
- post_data.delete("team_number")
154
-
155
- post_data
156
- else
157
- raise RequestError.new(404, could_not_find(post_data["team_number"], "number", "team"), {post_data: post_data})
158
- end
135
+ @models = model.all.psv_filter(params)
159
136
  end
160
- end
161
137
 
162
- # This supports match_number and competition_name
163
- # or match_number and competition (which is a Hash).
164
- def self.match_number_and_competition_to_match_id(post_data)
165
- return post_data unless post_data.is_a?(Hash)
166
-
167
- if post_data["match_number"] && !post_data["match_id"]
168
- if post_data["competition_name"] && (competition = Competition.find_by name: post_data["competition_name"])
169
- # Try to set the match to the already existing match.
170
- begin
171
- match = competition.matches.find_by number: post_data["match_number"]
172
- rescue ArgumentError, TypeError => e
173
- raise RequestError.new(422, e.message, {post_data: post_data})
174
- end
175
-
176
- # Create the match if necessary.
177
- begin
178
- match ||= Match.create(number: post_data["match_number"], competition_id: competition.id)
179
- rescue ArgumentError, TypeError => e
180
- raise RequestError.new(422, e.message, {post_data: post_data, competition_id: competition.id})
181
- end
182
-
183
- post_data["match_id"] = match.id
184
-
185
- post_data.delete("match_number")
186
- post_data.delete("competition_name")
187
-
188
- post_data
189
- elsif post_data["competition"] && post_data["competition"]["_id"] && (competition = Competition.find_by(id: post_data["competition"]["_id"]))
190
- # Try to set the match to the already existing match.
191
- match = competition.matches.find_by number: post_data["match_number"]
192
-
193
- # Create the match if necessary.
194
- begin
195
- match ||= Match.create(number: post_data["match_number"], competition_id: competition.id)
196
- rescue ArgumentError, TypeError => e
197
- raise RequestError.new(422, e.message, {post_data: post_data, competition_id: competition.id})
198
- end
199
-
200
- post_data["match_id"] = match.id
201
-
202
- post_data.delete("match_number")
203
- post_data.delete("competition")
204
-
205
- post_data
206
- else
207
- raise RequestError.new(422, "A current competition is not set. Please set it.", {post_data: post_data})
208
- end
209
- end
138
+ @models.to_json
210
139
  end
211
140
  end
212
141
  end
@@ -8,20 +8,9 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  require "json"
11
- require "frecon/models"
11
+ require "frecon/models/competition"
12
12
 
13
13
  module FReCon
14
14
  class CompetitionsController < Controller
15
- def self.teams(params)
16
- show_attribute params, :teams
17
- end
18
-
19
- def self.matches(params)
20
- show_attribute params, :matches
21
- end
22
-
23
- def self.records(params)
24
- show_attribute params, :records
25
- end
26
15
  end
27
16
  end
@@ -8,16 +8,9 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  require "json"
11
- require "frecon/models"
11
+ require "frecon/models/match"
12
12
 
13
13
  module FReCon
14
14
  class MatchesController < Controller
15
- def self.competition(params)
16
- show_attribute params, :competition
17
- end
18
-
19
- def self.records(params)
20
- show_attribute params, :records
21
- end
22
15
  end
23
16
  end
@@ -7,18 +7,10 @@
7
7
  # license with this program. If not, please see
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
+ require "json"
11
+ require "frecon/models/participation"
12
+
10
13
  module FReCon
11
14
  class ParticipationsController < Controller
12
- def self.create(request, params, post_data = nil)
13
- super(request, params, post_data || team_number_to_team_id(process_json_request(request)))
14
- end
15
-
16
- def self.competition(params)
17
- show_attribute params, :competition
18
- end
19
-
20
- def self.team(params)
21
- show_attribute params, :team
22
- end
23
15
  end
24
16
  end
@@ -8,17 +8,9 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  require "json"
11
- require "frecon/base"
12
- require "frecon/models"
11
+ require "frecon/models/record"
13
12
 
14
13
  module FReCon
15
14
  class RecordsController < Controller
16
- def self.create(request, params, post_data = nil)
17
- super(request, params, post_data || match_number_and_competition_to_match_id(team_number_to_team_id(process_json_request(request))))
18
- end
19
-
20
- def self.competition(params)
21
- show_attribute params, :competition
22
- end
23
15
  end
24
16
  end
@@ -12,16 +12,5 @@ require "frecon/models/robot"
12
12
 
13
13
  module FReCon
14
14
  class RobotsController < Controller
15
- def self.create(request, params, post_data = nil)
16
- super(request, params, post_data || team_number_to_team_id(process_json_request(request)))
17
- end
18
-
19
- def self.competition(params)
20
- show_attribute params, :competition
21
- end
22
-
23
- def self.team(params)
24
- show_attribute params, :team
25
- end
26
15
  end
27
16
  end
@@ -9,70 +9,9 @@
9
9
 
10
10
  require "json"
11
11
  require "frecon/base"
12
- require "frecon/models"
12
+ require "frecon/models/team"
13
13
 
14
14
  module FReCon
15
15
  class TeamsController < Controller
16
- # The `id` param will be a number or id.
17
- def self.find_model(params)
18
- (Team.find_by id: params[:id]) || (Team.find_by number: params[:id])
19
- end
20
-
21
- # Since Team has a special way of finding itself, we can make
22
- # the error message reflect this.
23
- def self.could_not_find(value, attribute = "id", model = model_name.downcase)
24
- if attribute == "id" && model == "team"
25
- "Could not find team of id or number #{value}!"
26
- else
27
- "Could not find #{model} of #{attribute} #{value}!"
28
- end
29
- end
30
-
31
- def self.records(params)
32
- @team = find_model params
33
-
34
- if @team
35
- if params[:competition_id]
36
- @competition = Competition.find params[:competition_id]
37
-
38
- if @competition
39
- @team.records.in(match_id: @competition.matches.map { |match| match.id }).to_json
40
- else
41
- raise RequestError.new(404, could_not_find(params[:competition_id], "id", "competition"), {params: params, team: @team})
42
- end
43
- else
44
- @team.records.to_json
45
- end
46
- else
47
- raise RequestError.new(404, could_not_find(params[:id], "id or number"), {params: params})
48
- end
49
- end
50
-
51
- def self.matches(params)
52
- @team = find_model params
53
-
54
- if @team
55
- # Ensure that the competition ID is valid.
56
- if params[:competition_id]
57
- @competition = Competition.find params[:competition_id]
58
-
59
- raise RequestError.new(404, could_not_find(params[:competition_id], "id", "competition"), {params: params, team: @team}) if @competition.nil?
60
- end
61
-
62
- @team.matches(params[:competition_id]).to_json
63
- else
64
- raise RequestError.new(404, could_not_find(params[:id], "id or number"), {params: params})
65
- end
66
- end
67
-
68
- def self.competitions(params)
69
- @team = find_model params
70
-
71
- if @team
72
- @team.competitions.to_json
73
- else
74
- raise RequestError.new(404, could_not_find(params[:id], "id or number"), {params: params})
75
- end
76
- end
77
16
  end
78
17
  end
@@ -8,7 +8,9 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  require "logger"
11
+
11
12
  require "mongoid"
13
+ require "frecon/mongoid/criteria"
12
14
 
13
15
  require "tempfile"
14
16
  require "yaml"
@@ -27,7 +29,7 @@ module FReCon
27
29
  else
28
30
  Mongoid.load!(File.join(File.dirname(__FILE__), "mongoid.yml"), environment)
29
31
  end
30
-
32
+
31
33
  if environment == :development
32
34
  Mongoid.logger.level = Logger::DEBUG
33
35
  Mongoid.logger = Logger.new($stdout)
data/lib/frecon/model.rb CHANGED
@@ -8,6 +8,7 @@
8
8
  # <http://opensource.org/licenses/MIT>.
9
9
 
10
10
  require "mongoid"
11
+ require "frecon/mongoid/criteria"
11
12
 
12
13
  module FReCon
13
14
  class Model
@@ -18,6 +19,16 @@ module FReCon
18
19
  include Mongoid::Attributes::Dynamic
19
20
 
20
21
  validate :no_invalid_relations
22
+
23
+ self.class_variable_set(:@@attributes, [])
24
+
25
+ def self.register_routable_relation(method, attribute)
26
+ self.class_variable_get(:@@attributes) << {method: method, type: :relation, attribute: attribute}
27
+ end
28
+
29
+ def self.register_routable_attribute(method, attribute)
30
+ self.class_variable_get(:@@attributes) << {method: method, type: :attribute, attribute: attribute}
31
+ end
21
32
  end
22
33
  end
23
34
 
@@ -21,15 +21,21 @@ module FReCon
21
21
  validates :name, uniqueness: true
22
22
 
23
23
  def records
24
- matches = self.matches
25
-
26
24
  Record.in match_id: matches.map(&:id)
27
25
  end
28
26
 
29
- def teams
30
- participations = self.participations
27
+ def robots
28
+ Robot.in id: participations.map(&:robot_id)
29
+ end
31
30
 
32
- Team.in id: participations.map(&:team_id)
31
+ def teams
32
+ Team.in id: robots.map(&:team_id)
33
33
  end
34
+
35
+ register_routable_relation :matches, "matches"
36
+ register_routable_relation :participations, "participations"
37
+ register_routable_relation :records, "records"
38
+ register_routable_relation :robots, "robots"
39
+ register_routable_relation :teams, "teams"
34
40
  end
35
41
  end
@@ -21,5 +21,23 @@ module FReCon
21
21
  has_many :records, dependent: :destroy
22
22
 
23
23
  validates :number, :competition_id, presence: true
24
+
25
+ def participations
26
+ Participation.in id: records.map(&:participation_id)
27
+ end
28
+
29
+ def robots
30
+ Robot.in id: participations.map(&:robot_id)
31
+ end
32
+
33
+ def teams
34
+ Team.in id: robots.map(&:team_id)
35
+ end
36
+
37
+ register_routable_relation :competition, "competition"
38
+ register_routable_relation :records, "records"
39
+ register_routable_relation :participations, "participations"
40
+ register_routable_relation :robots, "robots"
41
+ register_routable_relation :teams, "teams"
24
42
  end
25
43
  end
@@ -11,10 +11,24 @@ require "frecon/model"
11
11
 
12
12
  module FReCon
13
13
  class Participation < Model
14
+ belongs_to :robot
14
15
  belongs_to :competition
15
- belongs_to :team
16
+ has_many :records, dependent: :destroy
16
17
 
17
- validates :competition_id, :team_id, presence: true
18
- validates :team_id, uniqueness: { scope: :competition_id }
18
+ validates :robot_id, :competition_id, presence: true
19
+
20
+ def team
21
+ robot.team
22
+ end
23
+
24
+ def matches
25
+ competition.matches
26
+ end
27
+
28
+ register_routable_relation :robot, "robot"
29
+ register_routable_relation :team, "team"
30
+ register_routable_relation :competition, "competition"
31
+ register_routable_relation :matches, "matches"
32
+ register_routable_relation :records, "records"
19
33
  end
20
34
  end
@@ -16,12 +16,26 @@ module FReCon
16
16
  field :position, type: Position
17
17
 
18
18
  belongs_to :match
19
- belongs_to :team
19
+ belongs_to :participation
20
20
 
21
- validates :position, :match_id, :team_id, presence: true
21
+ validates :position, :match_id, :participation_id, presence: true
22
22
 
23
23
  def competition
24
- self.match.competition
24
+ match.competition
25
25
  end
26
+
27
+ def robot
28
+ participation.robot
29
+ end
30
+
31
+ def team
32
+ participation.robot.team
33
+ end
34
+
35
+ register_routable_relation :match, "match"
36
+ register_routable_relation :competition, "competition"
37
+ register_routable_relation :participation, "participation"
38
+ register_routable_relation :robot, "robot"
39
+ register_routable_relation :team, "team"
26
40
  end
27
41
  end
@@ -14,10 +14,27 @@ module FReCon
14
14
  # This is an optional field we included for organization.
15
15
  field :name, type: String
16
16
 
17
- belongs_to :competition
18
17
  belongs_to :team
18
+ has_many :participations, dependent: :destroy
19
19
 
20
- validates :competition_id, :team_id, presence: true
21
- validates :team_id, uniqueness: { scope: :competition_id }
20
+ validates :team_id, presence: true
21
+
22
+ def competitions
23
+ Competition.in id: participations.map(&:competition_id)
24
+ end
25
+
26
+ def records
27
+ Record.in participation_id: participations.map(&:id)
28
+ end
29
+
30
+ def matches
31
+ Match.in id: records.map(&:match_id).uniq
32
+ end
33
+
34
+ register_routable_relation :team, "team"
35
+ register_routable_relation :participations, "participations"
36
+ register_routable_relation :competitions, "competitions"
37
+ register_routable_relation :records, "records"
38
+ register_routable_relation :matches, "matches"
22
39
  end
23
40
  end
@@ -16,9 +16,8 @@ module FReCon
16
16
  field :location, type: String
17
17
  field :logo_path, type: String
18
18
  field :name, type: String
19
-
20
- has_many :participations, dependent: :destroy
21
- has_many :records, dependent: :destroy
19
+
20
+ has_many :robots, dependent: :destroy
22
21
 
23
22
  validates :number, presence: true, uniqueness: true, numericality: { greater_than: 0 }
24
23
 
@@ -27,20 +26,28 @@ module FReCon
27
26
  find_by number: team_number
28
27
  end
29
28
 
29
+ def participations
30
+ Participation.in robot_id: robots.map(&:id)
31
+ end
32
+
30
33
  def competitions
31
34
  Competition.in id: participations.map(&:competition_id)
32
35
  end
33
36
 
34
- # Returns all of the matches that this team has been in.
35
- # Optionally, returns the matches that this team has played
36
- # in a certain competition.
37
- def matches(competition_id = nil)
38
- matches = Match.in record_id: self.records.map(&:id)
39
- matches = matches.where competition_id: competition_id unless competition_id.nil?
37
+ def records
38
+ Record.in participation_id: participations.map(&:id)
39
+ end
40
40
 
41
- matches
41
+ def matches
42
+ Match.in competition_id: competitions.map(&:id)
42
43
  end
43
-
44
+
45
+ register_routable_relation :robots, "robots"
46
+ register_routable_relation :participations, "participations"
47
+ register_routable_relation :competitions, "competitions"
48
+ register_routable_relation :records, "records"
49
+ register_routable_relation :matches, "matches"
50
+
44
51
  # alias_method works by default solely on instance
45
52
  # methods, so change context to the metaclass of
46
53
  # Team and do aliasing there.
@@ -48,6 +55,5 @@ module FReCon
48
55
  alias_method :with_number, :number
49
56
  alias_method :that_has_number, :number
50
57
  end
51
-
52
58
  end
53
59
  end
@@ -0,0 +1,43 @@
1
+ # lib/frecon/mongoid/criteria.rb
2
+ #
3
+ # Copyright (C) 2015 Christopher Cooper, Sam Craig, Tiger Huang, Vincent Mai, Sam Mercier, and Kristofer Rye
4
+ #
5
+ # This file is part of FReCon, an API for scouting at FRC Competitions, which is
6
+ # licensed under the MIT license. You should have received a copy of the MIT
7
+ # license with this program. If not, please see
8
+ # <http://opensource.org/licenses/MIT>.
9
+
10
+ require "mongoid"
11
+
12
+ module Mongoid
13
+ class Criteria
14
+ def psv_filter(psv_parameters = {})
15
+ collection = self
16
+
17
+ psv_parameters.each do |psv_string, comparison_value|
18
+ psv_keys = psv_string.split(" ").map do |psv_key|
19
+ psv_key.to_sym
20
+ end.reverse
21
+
22
+ comparison_key = psv_keys.shift
23
+
24
+ if comparison_value.length == 0 || comparison_value == "__nil__"
25
+ comparison_hash = {comparison_key => nil}
26
+ else
27
+ comparison_hash = {comparison_key => comparison_value}
28
+ end
29
+
30
+ psv_keys.each do |model|
31
+ model_id = (model.to_s + '_id').to_sym
32
+ model_class = ("FReCon::" + model.to_s.capitalize).constantize
33
+
34
+ comparison_hash = {model_id => model_class.in(comparison_hash).map(&:id)}
35
+ end
36
+
37
+ collection = collection.in(comparison_hash)
38
+ end
39
+
40
+ collection
41
+ end
42
+ end
43
+ end
data/lib/frecon/routes.rb CHANGED
@@ -11,180 +11,111 @@ require "frecon/controllers"
11
11
 
12
12
  module FReCon
13
13
  module Routes
14
- def self.resource_routes(base, name, controller, methods = [:create, :update, :delete, :show, :index])
15
- if methods.include?(:create)
16
- base.post "/#{name}" do
17
- begin
18
- controller.create request, params
19
- rescue RequestError => e
20
- e.return_value
21
- end
22
- end
23
- end
24
-
25
- if methods.include?(:update)
26
- base.put "/#{name}/:id" do
27
- begin
28
- controller.update request, params
29
- rescue RequestError => e
30
- e.return_value
31
- end
32
- end
33
- end
34
-
35
- if methods.include?(:delete)
36
- base.delete "/#{name}/:id" do
37
- begin
38
- controller.delete params
39
- rescue RequestError => e
40
- e.return_value
41
- end
42
- end
43
- end
44
-
45
- if methods.include?(:show)
46
- base.get "/#{name}/:id" do
47
- begin
48
- controller.show params
49
- rescue RequestError => e
50
- e.return_value
51
- end
52
- end
53
- end
54
-
55
- if methods.include?(:index)
56
- base.get "/#{name}" do
57
- begin
58
- controller.index params
59
- rescue RequestError => e
60
- e.return_value
61
- end
62
- end
63
- end
64
- end
65
-
66
- def self.included(base)
67
- resource_routes base, "teams", TeamsController
68
-
69
- base.get "/teams/:id/records/?:competition_id?" do
14
+ def self.resource_routes(base, name, controller)
15
+ base.post "/#{name}" do
70
16
  begin
71
- TeamsController.records params
17
+ controller.create request, params
72
18
  rescue RequestError => e
73
19
  e.return_value
74
20
  end
75
21
  end
76
22
 
77
- base.get "/teams/:id/matches/?:competition_id?" do
23
+ base.put "/#{name}/:id" do
78
24
  begin
79
- TeamsController.matches params
25
+ controller.update request, params
80
26
  rescue RequestError => e
81
27
  e.return_value
82
28
  end
83
29
  end
84
30
 
85
- base.get "/teams/:id/competitions" do
31
+ base.delete "/#{name}/:id" do
86
32
  begin
87
- TeamsController.competitions params
33
+ controller.delete params
88
34
  rescue RequestError => e
89
35
  e.return_value
90
36
  end
91
37
  end
92
38
 
93
- resource_routes base, "competitions", CompetitionsController
94
-
95
- base.get "/competitions/:id/teams" do
39
+ base.get "/#{name}/:id" do
96
40
  begin
97
- CompetitionsController.teams params
41
+ controller.show params
98
42
  rescue RequestError => e
99
43
  e.return_value
100
44
  end
101
45
  end
102
46
 
103
- base.get "/competitions/:id/matches" do
47
+ base.get "/#{name}" do
104
48
  begin
105
- CompetitionsController.matches params
49
+ controller.index params
106
50
  rescue RequestError => e
107
51
  e.return_value
108
52
  end
109
53
  end
54
+ end
110
55
 
111
- base.get "/competitions/:id/records" do
112
- begin
113
- CompetitionsController.records params
114
- rescue RequestError => e
115
- e.return_value
116
- end
117
- end
56
+ def self.attribute_routes(base, name, controller)
57
+ model = controller.model
118
58
 
119
- resource_routes base, "matches", MatchesController
59
+ model_attribute_methods = model.class_variable_get(:@@attributes)
120
60
 
121
- base.get "/matches/:id/records" do
122
- begin
123
- MatchesController.records params
124
- rescue RequestError => e
125
- e.return_value
126
- end
127
- end
61
+ model_attribute_methods.each do |model_attribute_method|
62
+ base.get "/#{name}/:id/#{model_attribute_method[:attribute]}" do
63
+ begin
64
+ @model = controller.find_model(params)
128
65
 
129
- base.get "/matches/:id/competition" do
130
- begin
131
- MatchesController.competition params
132
- rescue RequestError => e
133
- e.return_value
134
- end
135
- end
66
+ params.delete("id")
136
67
 
137
- resource_routes base, "records", RecordsController
68
+ result = @model.method(model_attribute_method[:method]).call
138
69
 
139
- base.get "/records/:id/competition" do
140
- begin
141
- RecordsController.competition params
142
- rescue RequestError => e
143
- e.return_value
70
+ if result.is_a? Mongoid::Criteria
71
+ params.delete("splat")
72
+ params.delete("captures")
73
+
74
+ result.psv_filter(params).to_json
75
+ else
76
+ result.to_json
77
+ end
78
+ rescue RequestError => e
79
+ e.return_value
80
+ end
144
81
  end
145
82
  end
83
+ end
146
84
 
85
+ def self.included(base)
86
+ resource_routes base, "teams", TeamsController
87
+ resource_routes base, "competitions", CompetitionsController
88
+ resource_routes base, "matches", MatchesController
89
+ resource_routes base, "records", RecordsController
147
90
  resource_routes base, "robots", RobotsController
91
+ resource_routes base, "participations", ParticipationsController
148
92
 
149
- base.get "/robots/:id/competition" do
150
- begin
151
- RobotsController.competition params
152
- rescue RequestError => e
153
- e.return_value
154
- end
155
- end
93
+ attribute_routes base, "teams", TeamsController
94
+ attribute_routes base, "competitions", CompetitionsController
95
+ attribute_routes base, "matches", MatchesController
96
+ attribute_routes base, "records", RecordsController
97
+ attribute_routes base, "robots", RobotsController
98
+ attribute_routes base, "participations", ParticipationsController
156
99
 
157
- base.get "/robots/:id/team" do
158
- begin
159
- RobotsController.team params
160
- rescue RequestError => e
161
- e.return_value
162
- end
100
+ base.before do
101
+ params.delete("_")
163
102
  end
164
103
 
165
- resource_routes base, "participations", ParticipationsController
166
-
167
- base.get "/participations/:id/competition" do
104
+ base.get "/dump" do
168
105
  begin
169
- ParticipationsController.competition params
106
+ DumpController.full params
170
107
  rescue RequestError => e
171
108
  e.return_value
172
109
  end
173
110
  end
174
111
 
175
- base.get "/participations/:id/team" do
176
- begin
177
- ParticipationsController.team params
178
- rescue RequestError => e
179
- e.return_value
180
- end
181
- end
112
+ if ENV["PRINT_ROUTES"]
113
+ base.routes.each do |verb, routes|
114
+ puts "#{verb}:"
182
115
 
183
- base.get "/dump" do
184
- begin
185
- DumpController.full params
186
- rescue RequestError => e
187
- e.return_value
116
+ routes.each do |route|
117
+ puts " #{route[0]}"
118
+ end
188
119
  end
189
120
  end
190
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frecon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Craig
@@ -106,6 +106,7 @@ files:
106
106
  - lib/frecon/models/robot.rb
107
107
  - lib/frecon/models/team.rb
108
108
  - lib/frecon/mongoid.yml
109
+ - lib/frecon/mongoid/criteria.rb
109
110
  - lib/frecon/position.rb
110
111
  - lib/frecon/request_error.rb
111
112
  - lib/frecon/routes.rb