Skip to content

Commit

Permalink
Tobias: Sprout Tobias Gizmo
Browse files Browse the repository at this point in the history
- #1
- zinc-collective#709

- For a #9 to leverage
  the behavior we described, we need a way to put tobias on the web.
  zinc-collective#709 are the equivalent
  of an "App" in the Convene world.

- Note: `Gizmo` and `Furniture` are equivalent. We probably should
  finish zinc-collective#1472

- The migration change makes sure that ahttps://github.com//issues/4
  is connected to #1
  • Loading branch information
zspencer committed Mar 25, 2024
1 parent b1b3055 commit 07eb144
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/furniture/tobias.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
class Tobias
class Tobias < Furniture
has_many :trusts, inverse_of: :tobias
default_scope { where(furniture_kind: "tobias") }
location(parent: :room)
end

# TOBIAS is hard to pluralize... Rails presumed TOBIAS was plural,
# So this tells Rails that TOBIAS is the singular form, and that TOBIASes
# is the plural.
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.plural(/^(tobias)$/i, '\1\2es')
inflect.singular(/^(tobias)es/i, '\1')
end
9 changes: 9 additions & 0 deletions app/furniture/tobias/record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Tobias
class Record < ApplicationRecord
self.abstract_class = true

def self.model_name
@_model_name ||= ActiveModel::Name.new(self, ::Tobias)
end
end
end
9 changes: 9 additions & 0 deletions app/furniture/tobias/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Tobias
class Routes
def self.append_routes(router)
router.resources :tobiases, module: "tobias" do
router.resources :trusts
end
end
end
end
6 changes: 5 additions & 1 deletion app/furniture/tobias/trust.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class Tobias
class Trust < ApplicationRecord
class Trust < Record
self.table_name = "tobias_trusts"

belongs_to :tobias, inverse_of: :trusts

location(parent: :tobias)

has_many :beneficiaries, inverse_of: :trust, dependent: :destroy
has_many :payouts, inverse_of: :trust, dependent: :destroy
end
Expand Down
1 change: 1 addition & 0 deletions app/models/furniture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def self.registry
marketplace: ::Marketplace::Marketplace,
livestream: ::Livestream,
section_navigation: SectionNavigation::SectionNavigation,
tobias: Tobias,
embedded_form: EmbeddedForm
}
end
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20240127063826_create_tobias_payouts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class CreateTobiasPayouts < ActiveRecord::Migration[7.1]
def change
create_table :tobias_trusts, id: :uuid do |t|
t.references :tobias, type: :uuid, foreign_key: {to_table: :furnitures}
t.timestamps
end

Expand Down
7 changes: 5 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 50
t.string "scope"
t.datetime "created_at", precision: nil
t.datetime "created_at"
t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
Expand Down Expand Up @@ -291,7 +291,7 @@
t.string "email", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "operator", default: false
t.boolean "operator", default: false, null: false
t.index ["email"], name: "index_people_on_email", unique: true
end

Expand Down Expand Up @@ -361,8 +361,10 @@
end

create_table "tobias_trusts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "tobias_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["tobias_id"], name: "index_tobias_trusts_on_tobias_id"
end

create_table "utility_hookups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
Expand Down Expand Up @@ -404,4 +406,5 @@
add_foreign_key "tobias_payments", "tobias_beneficiaries", column: "beneficiary_id"
add_foreign_key "tobias_payments", "tobias_payouts", column: "payout_id"
add_foreign_key "tobias_payouts", "tobias_trusts", column: "trust_id"
add_foreign_key "tobias_trusts", "furnitures", column: "tobias_id"
end
5 changes: 5 additions & 0 deletions spec/tobias/factories/tobias_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :tobias do
room
end
end
3 changes: 3 additions & 0 deletions spec/tobias/factories/trust_factory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require_relative "tobias_factory"

FactoryBot.define do
factory :tobias_trust, class: "Tobias::Trust" do
tobias
end
end

0 comments on commit 07eb144

Please sign in to comment.