Class Product
In: app/models/product.rb
Parent: ActiveRecord::Base

プロダクト(機能)のモデル。

Methods

Constants

LABEL_TYPE = [ [N_("Product|type|Type 1"), "ProductSingle"], [N_("Product|type|Type 2"), "ProductMultiple"], [N_("Product|type|Type 3"), "ProductDetailed"], ]

External Aliases

root -> nested_set_root
children -> nested_set_children
name -> title

Public Class methods

key についての情報を返す。

[Source]

     # File app/models/product.rb, line 99
 99:   def self.current(key)
100:     ccache = CacheEachRequest.current
101:     ccache[:product] ||= {}
102:     ccache[:product][:root] ||= root
103:     ccache[:product][key] ||= yield root
104:   end

エラーメッセージのために attributes を属性に持つインスタンスを返す。

[Source]

    # File app/models/product.rb, line 84
84:   def self.for_error_message(attributes)
85:     product = self.new(attributes)
86:     product.name_po ||= 0
87:     if product.valid?
88:       raise "[bug] product must be with errors at here"
89:     end
90:     return product
91:   end

権限によって閲覧が不可能と指定されている全てのプロダクトを返す。

[Source]

     # File app/models/product.rb, line 121
121:   def self.invisible
122:     Product.current(:invisible) do |r|
123:       with_scope(:find => {:conditions => Permission.invisible_conditions(:product)}) { r.all_children }
124:     end
125:   end

権限によって変更が可能と指定されている全てのプロダクトを返す。

[Source]

     # File app/models/product.rb, line 107
107:   def self.modifiable
108:     Product.current(:modifiable) do |r|
109:       with_scope(:find => {:conditions => Permission.modifiable_conditions(:product)}) { r.all_children }
110:     end
111:   end

閲覧が可能、または閲覧が可能な子孫を持つプロダクトを返す。

[Source]

     # File app/models/product.rb, line 128
128:   def self.necessary
129:     Product.current(:necessary) do |r|
130:       top = Product.permissible.inject([]) {|seed,m| (seed.include? m) ? seed : (seed | m.self_and_ancestors)} - [r]
131:       bot = Product.invisible.inject([])   {|seed,m| (seed.include? m) ? seed : (seed | m.full_set)}
132:       mid = (r.all_children - top - bot).reject {|m| (top & m.ancestors).empty?}
133:       top | mid
134:     end
135:   end

権限によって閲覧が可能と指定されている全てのプロダクトを返す。

[Source]

     # File app/models/product.rb, line 114
114:   def self.permissible
115:     Product.current(:permissible) do |r|
116:       with_scope(:find => {:conditions => Permission.permissible_conditions(:product)}) { r.all_children }
117:     end
118:   end

メニューレイアウトでの根を返す。

[Source]

    # File app/models/product.rb, line 94
94:   def self.root
95:     find(:first, :conditions => "products.parent_id IS NULL", :order => "products.id")
96:   end

Public Instance methods

necessary な子プロダクト全体を返す。

[Source]

     # File app/models/product.rb, line 138
138:   def children
139:     @children ||= nested_set_children & Product.necessary
140:   end

x に関連する文書のノード全体を返す。 (削除されているノードを参照している辺やパスは削除する。)

[Source]

     # File app/models/product.rb, line 202
202:   def document_nodes_for(x)
203:     existing, removed = DocumentEdge.find(:all, :conditions => {:from_product_id => id, :from_id => x.id, :from_type => x.class.to_s}).select {|e| e.to_product.visible?}.partition(&:to)
204:     removed.each do |e|
205:       e.destroy
206:       e.document_paths.each(&:destroy)
207:     end
208:     return existing.map(&:to)
209:   end

x に関連付けられている文書を返す。 (削除されているノードを参照している文書は削除する。)

[Source]

     # File app/models/product.rb, line 192
192:   def documents_for(x)
193:     rels, removed = Document.find(:all, :conditions => {:relatable_product_id => id, :relatable_id => x.id, :relatable_type => x.class.to_s}).select {|d| d.target_product.visible?}.partition(&:target)
194:     removed.each(&:destroy)
195:     alts, removed = Document.find(:all, :conditions => {:target_product_id => id, :target_id => x.id, :target_type => x.class.to_s}).select {|d| d.relatable_product.visible?}.partition(&:relatable)
196:     removed.each(&:destroy)
197:     return rels | alts
198:   end

アプリケーションの管理者によって用意される画面を返す。

[Source]

     # File app/models/product.rb, line 186
186:   def master_displays
187:     displays.find(:all, :conditions => {:type => %w|DisplayToList DisplayToShow DisplayToEdit DisplayToNew|})
188:   end

model_name からモデル名を返す。

[Source]

     # File app/models/product.rb, line 181
181:   def model_class
182:     @model_class ||= model_name.constantize
183:   end

階層化された権限にしたがって変更可能かどうかを判定する。

[Source]

     # File app/models/product.rb, line 143
143:   def modifiable?
144:     return @modifiable if defined?(@modifiable)
145:     return @modifiable = true if Product.modifiable.include?(self)
146:     return @modifiable = false if Product.permissible.include?(self)
147:     return @modifiable = false if Product.invisible.include?(self)
148:     return @modifiable = parent.modifiable? if parent
149:     return @modifiable = false
150:   end

URL を構成するためのオプションを返す。

[Source]

     # File app/models/product.rb, line 162
162:   def url_options
163:     return @url_options if defined?(@url_options)
164:     return {} unless self.motion
165:     @url_options = {}
166:     self.motion.scan(/(\w+)=(\w+)/) do |key, value|
167:       @url_options[key.to_sym] = value
168:     end
169:     return @url_options
170:   end

階層化された権限にしたがって利用可能かどうかを判定する。

[Source]

     # File app/models/product.rb, line 153
153:   def visible?
154:     return @visible if defined?(@visible)
155:     return @visible = true if Product.permissible.include?(self)
156:     return @visible = false if Product.invisible.include?(self)
157:     return @visible = parent.visible? if parent
158:     return @visible = false
159:   end

[Source]

     # File app/models/product.rb, line 172
172:   def with_ajax?
173:     if /\A\// =~ motion
174:       return false
175:     else
176:       return true
177:     end
178:   end

[Validate]