Module: SocialStream::Routing::Mapper

Defined in:
lib/social_stream/routing/mapper.rb

Instance Method Summary collapse

Instance Method Details

#route_subjectsObject

Route subjects configured as SocialStream.routed_subjects in config/initializers/social_stream.rb

It supports namespaces, so setting

SocialStream.routed_subjects = [ ':site/clients' ]

and using

route_subjects do
  resources :posts
end

is equivalent to

namespace :site
  resources :clients
    resources :posts
  end
end


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/social_stream/routing/mapper.rb', line 26

def route_subjects
  SocialStream.routed_subjects.each do |name|
    ns = name.to_s.split('/')
    actor = ns.pop

    rts = -> {
      resources actor.pluralize do
        yield
      end
    }

    if ns.present?
      ns.reverse.inject(rts) { |lmda, n|
        proc do
          namespace n, &lmda
        end
      }.call
    else
      rts.call
    end
  end
end