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

🧹 Furniture: Complete the rename! #1209

Merged
merged 2 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ RSpec/ExampleLength:
- 'spec/furniture/journal/entries_request_spec.rb'
- 'spec/furniture/markdown_text_block_spec.rb'
- 'spec/furniture/marketplace/products_controller_request_spec.rb'
- 'spec/models/furniture_placement_spec.rb'
- 'spec/models/furniture_spec.rb'
- 'spec/models/membership_spec.rb'
- 'spec/models/room_spec.rb'
- 'spec/policies/room_policy_spec.rb'
- 'spec/requests/furniture_placements_controller_request_spec.rb'
- 'spec/requests/furnitures_controller_request_spec.rb'
Copy link
Member

Choose a reason for hiding this comment

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

You could just un-lint these 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

I was afeared of trying to do even more in this giganormoustrosity

Copy link
Member

Choose a reason for hiding this comment

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

If you put it in a separate commit I won't object!

But up to you, fine either way.

- 'spec/requests/rsvps_controller_request_spec.rb'
- 'spec/requests/spaces/invitations_request_spec.rb'
- 'spec/requests/spaces_controller_request_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def pundit_user
end

def space_repository
policy_scope(Space.includes(:rooms, entrance: [:furniture_placements]))
policy_scope(Space.includes(:rooms, entrance: [:furnitures]))
end

# Retrieves the room based upon the current_space and params
Expand Down
67 changes: 0 additions & 67 deletions app/controllers/furniture_placements_controller.rb

This file was deleted.

67 changes: 67 additions & 0 deletions app/controllers/furnitures_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class FurnituresController < ApplicationController
def edit
respond_to do |format|
format.turbo_stream
format.html
end
end

def create
respond_to do |format|
if furniture.save!
format.html do
redirect_to(
[furniture.room.space, furniture.room],
notice: t(".success", name: furniture.furniture.model_name.human)
)
end
format.turbo_stream
end
end
end

def update
respond_to do |format|
if furniture.update!(furniture_params)
format.html do
redirect_to(
[:edit, furniture.room.space, furniture.room],
notice: t(".success", name: furniture.furniture.model_name.human)
)
end
end
end
end

def destroy
furniture.furniture.destroy!
respond_to do |format|
format.html do
redirect_to(
[furniture.room.space, furniture.room],
notice: t(".success", name: furniture.furniture.model_name.human.titleize)
)
end

format.turbo_stream do
render turbo_stream: turbo_stream.remove(furniture)
end
end
end

helper_method def furniture
@furniture ||= find_or_build.tap do |furniture|
authorize(furniture)
end
end

def find_or_build
return current_room.furnitures.find(params[:id]) if params[:id]

current_room.furnitures.new(furniture_params)
end

def furniture_params
policy(Furniture).permit(params.require(:furniture))
end
end
2 changes: 1 addition & 1 deletion app/furniture/embedded_form.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class EmbeddedForm < FurniturePlacement
class EmbeddedForm < Furniture
def form_url=(form_url)
settings["form_url"] = form_url
end
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/journal/journal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Journal::Journal < FurniturePlacement
class Journal::Journal < Furniture
self.location_parent = :room

extend StripsNamespaceFromModelName
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/livestream.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Renders a Twitch Livestream in a Room
class Livestream < FurniturePlacement
class Livestream < Furniture
def channel=(channel)
settings["channel"] = channel
end
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/markdown_text_block.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Renders some HTML in a {Room}.
class MarkdownTextBlock < FurniturePlacement
class MarkdownTextBlock < Furniture
include RendersMarkdown

def to_html
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/marketplace/marketplace.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Marketplace
class Marketplace < FurniturePlacement
class Marketplace < Furniture
self.location_parent = :room

has_many :products, inverse_of: :marketplace, dependent: :destroy
Expand Down
4 changes: 2 additions & 2 deletions app/lib/space_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def self.append_routes(router)
router.resource :rsvp, only: %i[show update]
end
router.resources :rooms, only: %i[show edit update new create destroy] do
FurniturePlacement.append_routes(router)
router.resources :furniture_placements, only: %i[create edit update destroy]
Furniture.append_routes(router)
router.resources :furnitures, only: %i[create edit update destroy]
end

router.resources :utility_hookups
Expand Down
24 changes: 12 additions & 12 deletions app/models/blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def find_or_create!
def set_rooms
space_attributes.fetch(:rooms, []).each do |room_attributes|
room = space.rooms.find_or_initialize_by(name: room_attributes[:name])
room.update!(merge_non_empty(room.attributes, room_attributes).except(:name, :furniture_placements))
room.update!(merge_non_empty(room.attributes, room_attributes).except(:name, :furnitures))
add_furniture(room, room_attributes)
end
end

def add_furniture(room, room_attributes)
furniture_placements = room_attributes.fetch(:furniture_placements, {})
furniture_placements.each.with_index do |(furniture, settings), slot|
furniture_placement = room.furniture_placements
furnitures = room_attributes.fetch(:furnitures, {})
furnitures.each.with_index do |(furniture_kind, settings), slot|
furniture = room.furnitures
.find_or_initialize_by(slot: slot)
furniture_placement
.update!(settings: merge_non_empty(settings, furniture_placement.settings),
furniture_kind: furniture)
furniture
.update!(settings: merge_non_empty(settings, furniture.settings),
furniture_kind: furniture_kind)
end
end

Expand Down Expand Up @@ -102,32 +102,32 @@ def space_attributes
name: "Listed Room 1",
publicity_level: :listed,
access_level: :public,
furniture_placements: {
furnitures: {
markdown_text_block: {content: "# Welcome!"}
}
},
{
name: "Listed Room 2",
publicity_level: :listed,
access_level: :public,
furniture_placements: {}
furnitures: {}
},
{
name: "Unlisted Room 1",
publicity_level: :unlisted,
access_level: :public,
furniture_placements: {}
furnitures: {}
},
{
name: "Unlisted Room 2",
publicity_level: :unlisted,
access_level: :public,
furniture_placements: {}
furnitures: {}
},
{
name: "Entrance Hall",
publicity_level: :unlisted,
furniture_placements: {
furnitures: {
markdown_text_block: {content: "# Wooo!"}
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/models/furniture_placement.rb → app/models/furniture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# {Furniture} is configured using the {#settings} attribute, which is structured
# as JSON, so that {Furniture} can be tweaked and configured as appropriate for
# it's particular use case.
class FurniturePlacement < ApplicationRecord
class Furniture < ApplicationRecord
include RankedModel
include WithinLocation
self.location_parent = :room
Expand All @@ -24,7 +24,7 @@ class FurniturePlacement < ApplicationRecord
delegate :attributes=, to: :furniture, prefix: true

def furniture
@furniture ||= FurniturePlacement.from_placement(self)
@furniture ||= Furniture.from_placement(self)
end

def title
Expand All @@ -36,11 +36,11 @@ def utilities
end

def form_template
"furniture_placements/noop"
"furnitures/noop"
end

def configurable?
furniture.form_template != "furniture_placements/noop"
furniture.form_template != "furnitures/noop"
end

def write_attribute(name, value)
Expand Down Expand Up @@ -71,7 +71,7 @@ def self.append_routes(router)
end
end

# @return [FurniturePlacement]
# @return [Furniture]
def self.from_placement(placement)
furniture_class = registry.fetch(placement.furniture_kind.to_sym)
placement.becomes(furniture_class)
Expand Down
12 changes: 12 additions & 0 deletions app/models/furniture/serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Furniture::Serializer < ApplicationSerializer
# @return [Furniture]
alias_method :furniture, :resource

def to_json(*_args)
super.merge(
furniture: {
id: furniture.id
}
)
end
end
12 changes: 0 additions & 12 deletions app/models/furniture_placement/serializer.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def unlisted?
publicity_level&.to_sym == :unlisted
end

has_many :furniture_placements, dependent: :destroy_async
accepts_nested_attributes_for :furniture_placements
has_many :furnitures, dependent: :destroy_async
accepts_nested_attributes_for :furnitures

def full_slug
"#{space.slug}--#{slug}"
Expand Down
2 changes: 1 addition & 1 deletion app/models/room/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_json(*_args)
id: room.id,
slug: room.slug,
name: room.name,
furniture_placements: room.furniture_placements.map(&FurniturePlacement::Serializer.method(:new)).map(&:to_json)
furnitures: room.furnitures.map(&Furniture::Serializer.method(:new)).map(&:to_json)
}
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class FurniturePlacementPolicy < ApplicationPolicy
alias_method :furniture_placement, :object
delegate :space, to: :furniture_placement
class FurniturePolicy < ApplicationPolicy
alias_method :furniture, :object
delegate :space, to: :furniture

class Scope < ApplicationScope
def resolve
Expand All @@ -16,7 +16,7 @@ def show?
end

def update?
person&.operator? || person&.member_of?(furniture_placement.space)
person&.operator? || person&.member_of?(furniture.space)
end

alias_method :edit?, :update?
Expand All @@ -29,6 +29,6 @@ def permitted_attributes(_params)
end

def furniture_params
FurniturePlacement.registry.values.flat_map { |f| f.new.try(:attribute_names) }.compact
Furniture.registry.values.flat_map { |f| f.new.try(:attribute_names) }.compact
end
end
Loading