Skip to content

Commit

Permalink
move some modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Jul 3, 2016
1 parent fd32893 commit 703f358
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 50 deletions.
9 changes: 9 additions & 0 deletions app/controllers/concerns/enju_inventory/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module EnjuInventory
module Controller
extend ActiveSupport::Concern

def get_inventory_file
@inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
end
end
end
26 changes: 26 additions & 0 deletions app/models/concerns/enju_inventory/enju_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module EnjuInventory
module EnjuItem
extend ActiveSupport::Concern

included do
has_many :inventories, :dependent => :destroy
has_many :inventory_files, :through => :inventories
searchable do
integer :inventory_file_ids, :multiple => true
end

def inventory_items(inventory_file, mode = 'not_on_shelf')
item_ids = Item.pluck(:id)
inventory_item_ids = inventory_file.items.pluck('items.id')
case mode
when 'not_on_shelf'
Item.where(:id => (item_ids - inventory_item_ids))
when 'not_in_catalog'
Item.where(:id => (inventory_item_ids - item_ids))
end
rescue
nil
end
end
end
end
19 changes: 0 additions & 19 deletions lib/enju_inventory.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
require "enju_inventory/engine"
require "enju_inventory/item"

module EnjuInventory
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def enju_inventory
include EnjuInventory::InstanceMethods
end
end

module InstanceMethods
def get_inventory_file
@inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
end
end
end

ActiveRecord::Base.send :include, EnjuInventory::InventoryItem
ActionController::Base.send(:include, EnjuInventory)
31 changes: 0 additions & 31 deletions lib/enju_inventory/item.rb

This file was deleted.

2 changes: 2 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class ApplicationController < ActionController::Base

include EnjuLeaf::Controller
include EnjuLibrary::Controller
include EnjuInventory::Controller
after_action :verify_authorized
before_action :set_paper_trail_whodunnit

include Pundit
end

0 comments on commit 703f358

Please sign in to comment.