-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Garrisons #14
base: master
Are you sure you want to change the base?
Adds Garrisons #14
Changes from 3 commits
f607b64
5e6423f
fb28a33
9353c03
3494b36
420c1ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class CreateGarrisons < ActiveInteraction::Base | ||
object :match | ||
|
||
def execute | ||
GARRISONS_SETUP.keys.each do |garrison| | ||
Garrison.create!(match: match, territory_id: load_territory(garrison).id, name: garrison, x: GARRISONS_SETUP[garrison][:x], y: GARRISONS_SETUP[garrison][:y]) | ||
end | ||
end | ||
|
||
GARRISONS_SETUP = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Freeze mutable objects assigned to constants. |
||
winterfell: { x: 540, y: 655 }, | ||
pyke: { x: 0, y: 0 }, | ||
lannisport: { x: 0, y: 0 }, | ||
highgarden: { x: 0, y: 0 }, | ||
sunspear: { x: 0, y: 0 }, | ||
dragonstone: { x: 0, y: 0 } | ||
} | ||
|
||
private | ||
|
||
def board | ||
match.board | ||
end | ||
|
||
def number_of_players | ||
match.players.count | ||
end | ||
|
||
def load_territory(territory_slug) | ||
board.territories.select{ |territory| territory.slug == territory_slug.to_s }.first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [87/80] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at class body end. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Garrison < ActiveRecord::Base | ||
belongs_to :match | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateGarrisons < ActiveRecord::Migration | ||
def change | ||
create_table :garrisons do |t| | ||
t.string :name | ||
t.integer :match_id | ||
t.integer :territory_id | ||
t.integer :x | ||
t.integer :y | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
add_index :garrisons, [:match_id, :territory_id] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryGirl.define do | ||
factory :garrison do | ||
name "MyString" | ||
match_id 1 | ||
territory_id 1 | ||
x 1 | ||
y 1 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
|
||
RSpec.describe Garrison, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [163/80]