module Peta
class Item < ActiveRecord::Base
self.abstract_class = true
+ attr :boosters
# Dynamic ClassMethods
self.my_manifest.valid_encode_columns
end
- def self._extend_column_name
- self.my_manifest.extend_column_name
- end
-
def self.load_manifest
return nil unless self.my_manifest
r = self._valid_encode_columns
define_singleton_method("valid_encode_columns") do
r
end
- define_singleton_method("parent_model") do |tree_name|
- self.my_manifest.tree[tree_name].parent_model
- end
- define_singleton_method("child_models") do |tree_name|
- self.my_manifest.child_models tree_name
+ r = self.my_manifest.child_models
+ define_singleton_method("child_models") do
+ r
end
- define_singleton_method("child_element_names") do |tree_name|
- self.my_manifest.child_element_names tree_name
+ r = self.my_manifest.child_element_names
+ define_singleton_method("child_element_names") do
+ r
end
# Instance Methods
- n = self._extend_column_name
- define_singleton_method("extend_column_name") do
- n
- end
end
# ClassMethods
before_validation :valid_encode
+ def self.my_peta
+ Manifest.manifest.items[self.item_name]
+ end
+
def self.my_manifest
Manifest.manifest.models[self.item_name]
end
false
end
+ def self.element?
+ false
+ end
+
+ def self.root?
+ false
+ end
+
+ def self.parent_model
+ nil
+ end
+
def self.path_name with_engine = false
self.plural.underscore
end
+ def self.find_boost_name column_name
+ self.my_peta.find_boost_name column_name
+ end
+
+ def self.extend_column? column_name
+ self.my_peta.extend_column? column_name
+ end
+
def self.visible_count_options
nil
end
opt = {}
opt.merge!(self.show_opt)
item = self.find(item_id, opt)
- self.boost if self.boost_level_is_read?
+ item.boosts 'read'
raise ActiveRecord::Forbidden unless item.visible?(operators)
item
end
self.class.table_name
end
- def boost_level_is_read?
- self.class.my_peta.level == 'show'
- end
-
- def extend_column_name
- self.class.extend_column_name
- end
-
def path_name with_engine = false
self.class.path_name(with_engine)
end
end
end
- def engine
- Object.const_get self.attributes[self.extend_column_name]
+ def boosts level
+ self.class.my_peta.boost.each do |boost_name, boost_manifest|
+ next if level == 'read' and boost_manifest.level == 'post'
+ self.boost boost_manifest
+ end
end
- def my_engine_resource
- Manifest.manifest.system_resources.engine_resources[self.table_name]
+ def boost boost_manifest
+ @boosters ||= {}
+ @boosters[boost_manifest.name] = Locmare::Booster.new(boost_manifest, self)
end
- def engine?
- return false unless self.my_engine_resource
- self.my_engine_resource.resource_items.include? self.attributes[self.extend_column_name]
- end
+ def boosters
+ @boosters
+ end
- def boost
- return false unless self.engine?
- self.engine.boost self
- @boosted = true
- end
-
- def boosted?
- @boosted
+ def extend_column? column_name
+ self.class.extend_column? column_name
end
def supply_default
- self.my_peta.boost.each do |name, manifest|
- manifest.engine_model.engine_extend_module.supply_default
- end
+ self.class.my_peta.supply_defaults self
end
def overwrite