whoops - that was in the wrong spot. move swf_asset_parent.rb, refactor a bit
This commit is contained in:
parent
7a32b9c894
commit
8baa09d633
6 changed files with 14 additions and 26 deletions
|
@ -1,9 +1,7 @@
|
||||||
class Item < ActiveRecord::Base
|
class Item < ActiveRecord::Base
|
||||||
include SwfAssetParent
|
include SwfAssetParent
|
||||||
|
|
||||||
def swf_asset_type
|
SwfAssetType = 'object'
|
||||||
'object'
|
|
||||||
end
|
|
||||||
|
|
||||||
set_table_name 'objects' # Neo & PHP Impress call them objects, but the class name is a conflict (duh!)
|
set_table_name 'objects' # Neo & PHP Impress call them objects, but the class name is a conflict (duh!)
|
||||||
set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category
|
set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
class PetType < ActiveRecord::Base
|
class PetType < ActiveRecord::Base
|
||||||
include SwfAssetParent
|
include SwfAssetParent
|
||||||
|
|
||||||
def swf_asset_type
|
SwfAssetType = 'biology'
|
||||||
'biology'
|
|
||||||
end
|
|
||||||
|
|
||||||
BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml'))
|
BasicHashes = YAML::load_file(Rails.root.join('config', 'basic_type_hashes.yml'))
|
||||||
|
|
||||||
|
|
12
app/models/swf_asset_parent.rb
Normal file
12
app/models/swf_asset_parent.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
module SwfAssetParent
|
||||||
|
def swf_assets
|
||||||
|
rels = Table(ParentSwfAssetRelationship.table_name)
|
||||||
|
type = self.class::SwfAssetType
|
||||||
|
ids = ParentSwfAssetRelationship.
|
||||||
|
where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))).
|
||||||
|
select(rels[:swf_asset_id]).
|
||||||
|
all.map(&:swf_asset_id)
|
||||||
|
assets = Table(SwfAsset.table_name)
|
||||||
|
SwfAsset.where(assets[:id].in(ids)).all
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,10 +0,0 @@
|
||||||
module SwfAssetParent
|
|
||||||
def swf_assets
|
|
||||||
rels = Table(ParentSwfAssetRelationship.table_name)
|
|
||||||
swf_asset_ids = ParentSwfAssetRelationship.where(
|
|
||||||
rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(swf_asset_type))
|
|
||||||
).map(&:swf_asset_id)
|
|
||||||
swf_assets = Table(SwfAsset.table_name)
|
|
||||||
SwfAsset.where(swf_assets[:id].in(swf_asset_ids))
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe SwfAsset do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "swf_assets/index.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
Loading…
Reference in a new issue