Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/interactions/matches/create_garrisons.rb
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])

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]

end
end

GARRISONS_SETUP = {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [87/80]
Space missing to the left of {.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

end
5 changes: 5 additions & 0 deletions app/interactions/matches/create_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ def execute
match.create_board!
create_players(match, number_of_players)
# create_decks(match, use_tides_of_battle_cards)
create_garrisons(match)
match
end
end

private

def create_garrisons(match)
compose(CreateGarrisons, match: match)
end

# 3 players: Baratheon Lannister Stark
# 4 players: Baratheon Lannister Stark Greyjoy
# 5 players: Baratheon Lannister Stark Greyjoy Tyrell
Expand Down
3 changes: 3 additions & 0 deletions app/models/garrison.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Garrison < ActiveRecord::Base
belongs_to :match
end
2 changes: 0 additions & 2 deletions app/models/garrison_token.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Match < ActiveRecord::Base

has_many :players
has_one :board
has_many :garrisons
# has_many :decks
# has_one :wildlings_deck
# has_one :westeros_one_deck
Expand Down
1 change: 1 addition & 0 deletions app/serializers/match_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class MatchSerializer < ActiveModel::Serializer
attributes :id, :round, :iron_throne_track, :fiefdoms_track, :kings_court_track
has_one :board
has_many :players
has_many :garrisons
end
15 changes: 15 additions & 0 deletions db/migrate/20160606222125_create_garrisons.rb
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
14 changes: 13 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160524235332) do
ActiveRecord::Schema.define(version: 20160606222125) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -26,6 +26,18 @@

add_index "boards", ["match_id"], name: "index_boards_on_match_id", using: :btree

create_table "garrisons", force: :cascade do |t|
t.string "name"
t.integer "match_id"
t.integer "territory_id"
t.integer "x"
t.integer "y"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "garrisons", ["match_id", "territory_id"], name: "index_garrisons_on_match_id_and_territory_id", using: :btree

create_table "house_cards", force: :cascade do |t|
t.string "name", null: false
t.integer "x", default: 0, null: false
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/garrisons.rb
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
5 changes: 5 additions & 0 deletions spec/models/garrison_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

Choose a reason for hiding this comment

The 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