This sample app demonstrates SimpleMaster in a compact, game-like domain.
It is used to exercise column casting and association patterns (STI, polymorphic
belongs_to, has_many).
bundle install
cd examples/rails_sample
bundle exec rails db:prepare
bundle exec rails sDatabase settings live in examples/rails_sample/config/database.yml.
development: sqlite3 atexamples/rails_sample/db/development.sqlite3test: sqlite3 in-memory (:memory:)production: sqlite3 atexamples/rails_sample/db/production.sqlite3
If you need a different DB, edit config/database.yml or set DATABASE_URL.
SimpleMaster (masters) ActiveRecord
[Weapon] (STI: Gun, Blade) [Player] --< player_items >-- (polymorphic to Weapon/Armor/Potion)
[Armor] PlayerItem: belongs_to :item, polymorphic
[Potion]
[Level] --< players (lv) >-- [Player]
[Enemy] --< rewards >-- [Reward] (reward_type/reward_id -> Weapon/Armor/Potion)
- Weapon (
Gun,Blade)idtypenameattack(float)info(json, symbolize_names: true)metadata(json, symbolize_names: false)rarity(enum)flags(bitmask)- Notes: polymorphic target (PlayerItem, Reward)
- Armor
idnamedefence(float)- Notes: polymorphic target
- Potion
idnamehp(float)- Notes: polymorphic target
- Level
idlv(unique)attack(float)defence(float)hp(float)- Associations:
has_many :players(lv)
- Enemy
idnameis_boss(boolean)start_at(time)end_at(time)attackdefencehp- Associations:
has_many :rewards
- Reward
idenemy_idreward_typereward_id- Associations:
belongs_to :enemy; polymorphicbelongs_toWeapon/Armor/Potion
- Player
idnamelv- Associations:
belongs_to :level(lv);has_many :player_items;has_many :items, through: :player_items
- PlayerItem
player_iditem_typeitem_id- Associations:
belongs_to :player; polymorphicbelongs_to :item
Fixtures live in examples/rails_sample/fixtures/masters.
weapons.json(STI Gun/Blade),armors.json,potions.json,levels.json(useslvas unique key),enemies.json,rewards.json- Aim to include representative casts (float/json/globalize where useful) and polymorphic/has_many links.
simple_master/active_record/extension_spec.rb: AR↔master (belongs_to_master)simple_master/master/item_spec.rb: column casting and master associationssimple_master/master/filterable_spec.rb: find/find_by/all_by/all_insimple_master/master/cache_spec.rb: cache_method, cache_class_methodsimple_master/storage/loader_spec.rb: STI instantiation, diff applicationsimple_master/loader/marshal_loader_spec.rb: Marshal dump/load roundtripsimple_master/storage/dataset_spec.rb: dataset cache/diff duplication