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)
+ item.boosts 'read'
raise ActiveRecord::Forbidden unless item.visible?(operators)
item
end
{}
end
+ def self.fold_extend_settings params
+ self.my_peta.boost.each do |name, manifest|
+ my_settings = params[self.item_name][manifest.settings_column_name]
+ if my_settings.is_a?(Hash)
+ params[self.item_name][manifest.settings_column_name] = my_settings.to_json
+ end
+ end
+ self.child_models.each do |child_model|
+ child_model.fold_extend_settings params
+ end
+ end
+
#InstanceMethods
def item_name
self.class.table_name
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 self.fold_extend_settings params
- speech_balloon_settings = params[:speech_balloon][:settings]
- if speech_balloon_settings.is_a?(Hash)
- params[:speech_balloon][:settings] = speech_balloon_settings.to_json
- end
- balloon_settings = params[:speech_balloon][:balloon_attributes][:settings]
- if balloon_settings.is_a?(Hash)
- params[:speech_balloon][:balloon_attributes][:settings] = balloon_settings.to_json
- end
- speech_settings = params[:speech_balloon][:speech_attributes][:settings]
- if speech_settings.is_a?(Hash)
- params[:speech_balloon][:speech_attributes][:settings] = speech_settings.to_json
+ 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 engine
- Object.const_get self.attributes[self.extend_column_name]
+ def boost boost_manifest
+ @boosters ||= {}
+ @boosters[boost_manifest.name] = Locmare::Booster.new(boost_manifest, self)
end
- def my_engine_resource
- Manifest.manifest.system_resources.engine_resources[self.table_name]
- end
+ def boosters
+ @boosters
+ 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 boost
- return false unless self.engine?
- self.engine.boost self
- true
+ def extend_column? column_name
+ self.class.extend_column? column_name
end
def supply_default
+ self.class.my_peta.supply_defaults self
end
def overwrite
self.new_record? ? 'stored' : 'new'
end
+ def merge_dom_item_id attr, name = nil
+ if self.editize?
+ attr.merge({'id' => self.dom_item_id(name)})
+ else
+ attr
+ end
+ end
+
def tag_attributes name = nil, opt = {}
r = {
'data-pool_type' => self.dom_pool_type, 'data-id' => self.dom_id,
'data-item_name' => self.item_name
}
- r.merge!({'id' => self.dom_item_id(name)}) if self.editize?
+ r = self.merge_dom_item_id r, name
r.merge!(opt)
r
end
)
end
+ def post_attribute_key
+ self.dom_id
+ end
+
end
end