frecon 0.1.0 → 0.1.1
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 +4 -4
- data/bin/frecon +1 -1
- data/lib/frecon/base/variables.rb +11 -2
- data/lib/frecon/console.rb +1 -1
- data/lib/frecon/controllers/records_controller.rb +16 -3
- data/lib/frecon/database.rb +3 -3
- data/lib/frecon/model.rb +16 -1
- data/lib/frecon/server.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87a1e0ba2b53235ae6571889845af40b25e12222
|
4
|
+
data.tar.gz: 54af0be09f289107088b401d9b90490c0e8d333a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93bfbc489e1b4f92caa4737655750bbc0d86f1fe13a6e4e452e9ed170143e0ce66fb820a34d56a00eafea833a570c75f89cfc3903184a41d5fe98a6bfb0ea668
|
7
|
+
data.tar.gz: 8742321caf2e7c047af913e0520ef4e57877f006d731003eeed1351afb2cf5adf9bcb3fb0ccc1b0483493f459289a0d96872ebc614c00a112446c2ee435719cf
|
data/bin/frecon
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
3
|
# Allow running locally.
|
4
|
-
lib_directory = File.expand_path(
|
4
|
+
lib_directory = File.class_eval('expand_path(join(dirname(__FILE__), "..", "lib"))')
|
5
5
|
$LOAD_PATH.unshift(lib_directory) unless $LOAD_PATH.include?(lib_directory)
|
6
6
|
|
7
7
|
require "frecon"
|
@@ -1,4 +1,13 @@
|
|
1
1
|
module FReCon
|
2
|
-
|
3
|
-
|
2
|
+
VERSION = "0.1.1"
|
3
|
+
|
4
|
+
@environment_variable = :development
|
5
|
+
|
6
|
+
def self.environment
|
7
|
+
@environment_variable
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.environment=(arg)
|
11
|
+
@environment_variable = arg
|
12
|
+
end
|
4
13
|
end
|
data/lib/frecon/console.rb
CHANGED
@@ -11,15 +11,24 @@ module FReCon
|
|
11
11
|
# Change special post_data attributes.
|
12
12
|
# Convert team number to team id.
|
13
13
|
post_data = team_number_to_team_id(post_data)
|
14
|
+
return post_data if post_data.is_an?(Array)
|
14
15
|
|
15
16
|
# Convert match number and competition name to match id.
|
16
17
|
if post_data["match_number"] && !post_data["match_id"]
|
17
18
|
if post_data["competition_name"] && (competition = Competition.find_by name: post_data["competition_name"])
|
18
19
|
# Try to set the match to the already existing match.
|
19
|
-
|
20
|
+
begin
|
21
|
+
match = competition.matches.find_by number: post_data["match_number"]
|
22
|
+
rescue ArgumentError, TypeError => e
|
23
|
+
return [422, ErrorFormatter.format(e.message)]
|
24
|
+
end
|
20
25
|
|
21
26
|
# Create the match if necessary.
|
22
|
-
|
27
|
+
begin
|
28
|
+
match ||= Match.create(number: post_data["match_number"], competition_id: competition.id)
|
29
|
+
rescue ArgumentError, TypeError => e
|
30
|
+
return [422, ErrorFormatter.format(e.message)]
|
31
|
+
end
|
23
32
|
|
24
33
|
post_data["match_id"] = match.id
|
25
34
|
|
@@ -30,7 +39,11 @@ module FReCon
|
|
30
39
|
match = competition.matches.find_by number: post_data["match_number"]
|
31
40
|
|
32
41
|
# Create the match if necessary.
|
33
|
-
|
42
|
+
begin
|
43
|
+
match ||= Match.create(number: post_data["match_number"], competition_id: competition.id)
|
44
|
+
rescue ArgumentError, TypeError => e
|
45
|
+
return [422, ErrorFormatter.format(e.message)]
|
46
|
+
end
|
34
47
|
|
35
48
|
post_data["match_id"] = match.id
|
36
49
|
|
data/lib/frecon/database.rb
CHANGED
@@ -5,9 +5,9 @@ require "frecon/models"
|
|
5
5
|
|
6
6
|
module FReCon
|
7
7
|
class Database
|
8
|
-
def self.setup()
|
9
|
-
Mongoid.load!(File.join(File.dirname(__FILE__), "mongoid.yml"),
|
10
|
-
|
8
|
+
def self.setup(environment)
|
9
|
+
Mongoid.load!(File.join(File.dirname(__FILE__), "mongoid.yml"), environment)
|
10
|
+
|
11
11
|
Mongoid.logger.level = Logger::DEBUG
|
12
12
|
Mongoid.logger = Logger.new($stdout)
|
13
13
|
|
data/lib/frecon/model.rb
CHANGED
@@ -6,8 +6,23 @@ module FReCon
|
|
6
6
|
child.class_eval do
|
7
7
|
include Mongoid::Document
|
8
8
|
include Mongoid::Timestamps
|
9
|
-
include Mongoid::Attributes::Dynamic
|
9
|
+
include Mongoid::Attributes::Dynamic
|
10
|
+
|
11
|
+
validate :no_invalid_relations
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def no_invalid_relations
|
16
|
+
# Get all of the belongs_to fields (ends with "_id" and not "_id" because that is the id).
|
17
|
+
attributes.keys.select { |attribute| attribute.end_with?("_id") && attribute != "_id" }.each do |relation|
|
18
|
+
# Get the model for the belongs_to association.
|
19
|
+
model = "FReCon::".concat(relation.gsub(/_id\Z/, "").capitalize).constantize
|
20
|
+
errors.add(relation.to_sym, "is invalid") if relation_invalid(model, send(relation))
|
10
21
|
end
|
11
22
|
end
|
23
|
+
|
24
|
+
def relation_invalid(class_constant, id)
|
25
|
+
class_constant.find_by(id: id).nil?
|
26
|
+
end
|
12
27
|
end
|
13
28
|
end
|
data/lib/frecon/server.rb
CHANGED
@@ -8,14 +8,16 @@ module FReCon
|
|
8
8
|
class Server < Sinatra::Base
|
9
9
|
include Routes
|
10
10
|
|
11
|
-
configure do
|
12
|
-
Database.setup
|
13
|
-
end
|
14
|
-
|
15
11
|
before do
|
16
12
|
content_type "application/json"
|
17
13
|
end
|
18
14
|
|
15
|
+
def self.run!
|
16
|
+
Database.setup(FReCon.environment)
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
19
21
|
def self.start
|
20
22
|
run!
|
21
23
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Craig
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- lib/frecon/position.rb
|
96
96
|
- lib/frecon/routes.rb
|
97
97
|
- lib/frecon/server.rb
|
98
|
-
homepage: https://github.com/
|
98
|
+
homepage: https://github.com/frc-frecon/frecon
|
99
99
|
licenses: []
|
100
100
|
metadata: {}
|
101
101
|
post_install_message:
|