Module: Rys::FeaturedRoutes::Mapper

Defined in:
lib/rys/featured_routes.rb

Instance Method Summary collapse

Instance Method Details

#add_route(action, options) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rys/featured_routes.rb', line 5

def add_route(action, options)
  rys_feature = options.delete(:rys_feature)

  if options[:constraints] && rys_feature
    raise ArgumentError, 'You cannot combine :constraints with :rys_feature.'
  end

  if rys_feature
    options[:constraints] = lambda {|_| Rys::Feature.active?(rys_feature) }
  end

  super
end

#rys_feature(feature) ⇒ Object


19
20
21
22
# File 'lib/rys/featured_routes.rb', line 19

def rys_feature(feature)
  constraints = lambda {|_| Rys::Feature.active?(feature) }
  scope(constraints: constraints) { yield }
end