Class: ConcertoManykinds::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/concerto_manykinds/engine.rb

Instance Method Summary collapse

Instance Method Details

#plugin_info(plugin_info_class) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/concerto_manykinds/engine.rb', line 9

def plugin_info(plugin_info_class)
  @plugin_info ||= plugin_info_class.new do
    
    # Make the engine's controller accessible at /manykinds
    add_route("manykinds", ConcertoManykinds::Engine)

    # Some code to run at app boot
    init do
      Rails.logger.info "ConcertoManykinds: Initialization code is running"
    end

    # show the details alongside each template

    add_controller_hook "TemplatesController", :show, :before do
      @manykinds = Manykind.where(:template_id => @template.id)
      @manykind_new = Manykind.new
    end

    add_view_hook "TemplatesController", :sidebar, :partial => "concerto_manykinds/templates/details"

    # # show that the template is in use
  
    # add_controller_hook "TemplatesController", :show, :before do
    #   @schedules = Schedule.where(:template_id => @template.id)
    # end

    # add_view_hook "TemplatesController", :template_details, :partial => "concerto_template_scheduling/templates/in_use_by"

    # override the filtering by using an around filter and not yielding to it
    add_controller_hook "Subscription", :filter_contents, :around do
      allowed_kinds = Manykind.kinds_for(self.screen.template.id, self.field.id).collect {|r| r.kind_id }
      allowed_kinds << self.field.kind.id
      @contents.reject!{|c| !allowed_kinds.include?(c.kind_id)}
    end
  end
end