Skip to content

Commit

Permalink
refactor: transition from Virtus to dry-transaction for Service Layer…
Browse files Browse the repository at this point in the history
…, migrate Media Widget Parser to Plugins::Core, remove RSS logic, remove various non-core logic, various refactors
  • Loading branch information
toastercup committed Feb 26, 2018
1 parent fa7f6b6 commit 25eaf20
Show file tree
Hide file tree
Showing 37 changed files with 253 additions and 454 deletions.
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
cortex-exceptions (= 0.0.4)
devise (~> 4.3.0)
dry-struct (~> 0.4.0)
dry-transaction (~> 0.10.2)
dry-transaction (~> 0.11.0)
dry-types (~> 0.12.2)
elasticsearch-dsl (~> 0.1)
elasticsearch-model (~> 5.0)
Expand Down Expand Up @@ -172,9 +172,13 @@ GEM
dry-container (0.6.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.3)
dry-core (0.4.4)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.0)
dry-events (0.1.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4)
dry-equalizer (~> 0.2)
dry-logic (0.4.2)
dry-container (~> 0.2, >= 0.2.6)
dry-core (~> 0.2)
Expand All @@ -188,11 +192,11 @@ GEM
dry-equalizer (~> 0.2)
dry-types (~> 0.12, >= 0.12.2)
ice_nine (~> 0.11)
dry-transaction (0.10.2)
dry-transaction (0.11.0)
dry-container (>= 0.2.8)
dry-matcher (>= 0.5.0)
dry-monads (>= 0.0.1)
wisper (>= 1.6.0)
dry-events (>= 0.1.0)
dry-matcher (>= 0.7.0)
dry-monads (>= 0.4.0)
dry-types (0.12.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
Expand Down Expand Up @@ -257,7 +261,7 @@ GEM
actionpack (>= 3.0)
multi_json
request_store (>= 1.0)
graphiql-rails (1.4.8)
graphiql-rails (1.4.9)
rails
graphql (1.7.9)
guard (2.14.2)
Expand Down Expand Up @@ -546,7 +550,6 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
wisper (2.0.0)
xpath (3.0.0)
nokogiri (~> 1.8)

Expand Down
16 changes: 16 additions & 0 deletions app/controllers/concerns/cortex/decoratable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TODO: ContentTypes, Decorators or Contracts themselves should inform the system what the correct Decorator is, not a hardcoded concern method
module Cortex
module Decoratable
extend ActiveSupport::Concern

included do
def index_decorator(content_type)
content_type.decorators.find_by_name('Index')
end

def wizard_decorator(content_type)
content_type.decorators.find_by_name('Wizard')
end
end
end
end
17 changes: 9 additions & 8 deletions app/controllers/cortex/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

module Cortex
class ContentItemsController < AdminController
include ContentItemHelper
include PopupHelper
include Cortex::Decoratable
include Cortex::ContentItemHelper
include Cortex::PopupHelper

def index
@index = IndexDecoratorService.new(content_type: content_type)
@index = index_decorator(content_type)
@content_items = content_type.content_items.find_by_tenant(current_user.active_tenant)
add_breadcrumb content_type.name.pluralize
end
Expand All @@ -17,15 +18,15 @@ def new
# TODO: Should this hit the Plugin Transaction Layer?
@content_item.field_items << FieldItem.new(field: field)
end
@wizard = WizardDecoratorService.new(content_item: @content_item)
@wizard = wizard_decorator(@content_item.content_type)

add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
add_breadcrumb 'New'
end

def edit
@content_item = content_type.content_items.find_by_tenant(current_user.active_tenant).find_by_id(params[:id])
@wizard = WizardDecoratorService.new(content_item: @content_item)
@wizard = wizard_decorator(@content_item.content_type)

title = @content_item.field_items.find { |field_item| field_item.field.name == 'Title' }.data['text'] # TODO: refactor this hardcoded Field reference
add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
Expand All @@ -39,7 +40,7 @@ def update
rescue ActiveRecord::RecordInvalid => e
flash[:warning] = validation_message(e.message)
@content_item = content_item_reload(content_type.content_items.find_by_id(params[:id]))
@wizard = WizardDecoratorService.new(content_item: @content_item)
@wizard = wizard_decorator(@content_item.content_type)

title = @content_item.field_items.find { |field_item| field_item.field.name == 'Title' }.data['text'] # TODO: refactor this hardcoded Field reference
add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
Expand All @@ -55,11 +56,11 @@ def update

def create
begin
content_item.create
create_content_item
rescue ActiveRecord::RecordInvalid => e
flash[:warning] = validation_message(e.message)
@content_item = content_item_reload(content_type.content_items.new)
@wizard = WizardDecoratorService.new(content_item: @content_item)
@wizard = wizard_decorator(@content_item.content_type)

add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
add_breadcrumb 'New'
Expand Down
15 changes: 0 additions & 15 deletions app/controllers/cortex/rss/v2/rss_controller.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/helpers/cortex/content_item_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def content_item
@content_item ||= Cortex::ContentItemService.new(id: params[:id], content_item_params: content_item_params, current_user: current_user, state: params[:content_item][:state])
end

def create_content_item
CreateContentItemTransaction.new.call(id: params[:id], content_type: content_type,
content_item_params: content_item_params, current_user: current_user,
state: params[:content_item][:state])
end

def content_item_reload(content_item)
@content_item = content_item
content_type.fields.each do |field|
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/cortex/popup_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def media_image_content_items
end

def media_index
@media_index ||= IndexDecoratorService.new(content_type: media_content_type)
@media_index ||= media_content_type.decorators.find_by_name('Index')
end
end
end
78 changes: 0 additions & 78 deletions app/helpers/cortex/rss_helper.rb

This file was deleted.

53 changes: 0 additions & 53 deletions app/helpers/cortex/widget_parsers/media_helper.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/helpers/cortex/widget_parsers_helper.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/models/concerns/cortex/cortex_rss_spec/channel.rb

This file was deleted.

11 changes: 0 additions & 11 deletions app/models/concerns/cortex/cortex_rss_spec/item.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module SearchableContentItemForContentType
after_commit on: [:update] do
self.class.__elasticsearch__.delete_index!(index: content_items_index_name)
self.class.__elasticsearch__.create_index!(index: content_items_index_name, mappings: content_item_mappings)
# TODO: implement & move import to ContentItem
# TODO: implement & move import to ContentItem to mass-refresh all ContentItems for a ContentType
#self.class.__elasticsearch__.import()
end

Expand Down
16 changes: 1 addition & 15 deletions app/models/cortex/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,10 @@ class ContentItem < Cortex::ApplicationRecord
end

def publish_state
# TODO: move logic to Transaction
PublishStateService.new.content_item_state(self)
end

def rss_url(base_url, slug_field_id) # TODO: abstract RSS to separate app once API is implemented
slug = field_items.find_by_field_id(slug_field_id).data.values.join
"#{base_url}#{slug}"
end

def rss_date(date_field_id) # TODO: abstract RSS to separate app once API is implemented
date = field_items.find_by_field_id(date_field_id).data["timestamp"]
Date.parse(date).rfc2822
end

def rss_author(field_id) # TODO: abstract RSS to separate app once API is implemented
author = field_items.find_by_field_id(field_id).data["author_name"]
"[email protected] (#{author})"
end

# FieldItem and State Convenience Methods. TODO: move to concern? transactions?
def method_missing(method_name, *arguments, &block)
super unless dynamic_method?(method_name)
Expand Down
13 changes: 0 additions & 13 deletions app/models/cortex/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,5 @@ class ContentType < Cortex::ApplicationRecord
def self.permissions
Permission.select { |perm| perm.resource_type = self }
end

# TODO: remove these garbage `_decorator` methods
def wizard_decorator
decorators.find_by_name("Wizard")
end

def index_decorator
decorators.find_by_name("Index")
end

def rss_decorator
decorators.find_by_name("Rss")
end
end
end
Loading

0 comments on commit 25eaf20

Please sign in to comment.