ブラウザゲーム開発みたいのについて

今年の 4 月から IT エンジニアをやってます。もう 5 ヶ月ぐらい IT エンジニアをやってることになりました。ブラウザゲームの企画とプログラミングをやってます。

Rails でやってます。 RSpecテストファーストという普通の感じです。僕の開発スタイルで普通と違うのは以下 2 点ぐらい。

まず NDD を採用しています。 NDD については http://ssig33.com/blog/2010-08-05-1.html こちらを御参照ください。かなりストレスの高い開発手法なので気をつけてください。

もう一つですが、Web アプリケーションではデータべースのスキーマーをどう決めるかとかが重要だと思うのですが、個人的な事情(RDBMS スキルが微妙)と仕事上の事情(スケジュールがアレなのでがっちり設計してがっちりスキーマー決めるとか難しい)ので、以下のようなスキーマーを採用しています。

  create_table "entities", :force => true do |t|
    t.string   "key",        :null => false
    t.text     "body"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "entities", ["key"], :name => "index_entities_on_key", :unique => true

  create_table "indices", :force => true do |t|
    t.integer  "entity_id"
    t.string   "name"
    t.integer  "sort"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "indices", ["entity_id"], :name => "index_indices_on_entity_id"
  add_index "indices", ["name", "sort"], :name => "index_indices_on_name_and_sort"
  add_index "indices", ["name"], :name => "index_indices_on_name"

テーブルは以上二つ。モデルは

class Entity < ActiveRecord::Base
  has_many :indices

  def value
    MessagePack.unpack(self.body) rescue nil
  end

  def value= args
    self.body = args.to_msgpack
  end
end

class Index < ActiveRecord::Base
  belongs_to :entity
end

こんな感じ。

e = Entity.create(:key => "fuck", :body => {:unko => "unko"}.to_msgpack)
value = e.value
value["shit"] = "shit"
e.value = value
e.save
e2 = Entity.create(:key => "kill", :body => {:unko => {:unkooooo => ""}}.to_msgpack)
Index.create(:name => "fucking", :entity_id => e.id, :sort => 1)
Index.create(:name => "fucking", :entity_id => e2.id, :sort => 2)
Index.find(:all, :conditions => {:name => "fucking"}, :order => "sort desc", :include => :entity)

こんな感じで使う。 Facebook のやつとか Lang-8 の SimpleResource とかを AR だけでやってる感じです。スキーマレスな DB を MySQL 上で実現できます。MySQL しか使ってないからトランザクションも使えます(使ってないけど)。スキーマレスなので思いついたら適当にスキーマを追加出来るし、機能追加などの時もいきなり機能の実装をはじめられます。

オススメ、と言えるやり方なのかどうかは微妙。 Rails の原則には真っ向勝負を挑んでいるわけだし。

コントローラーを厚くするのは微妙なので apps/model 以下にビジネスロジックを実装したコードが散っている。

もうちょっとかっこよくスキーマレス DB を Rails 上で使える方法が欲しい(SimpleResource はテストが難しいので却下)。

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy