Module: Aygabtu::Scope::Action

Defined in:
lib/aygabtu/scope/action.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.factory_methodsObject



33
34
35
# File 'lib/aygabtu/scope/action.rb', line 33

def self.factory_methods
  [:action]
end

Instance Method Details

#action(*actions) ⇒ Object



4
5
6
7
8
9
# File 'lib/aygabtu/scope/action.rb', line 4

def action(*actions)
  raise "nesting/chaining action scopes makes no sense" if @data[:action]

  new_data = @data.dup.merge(actions: actions.map(&:to_s))
  self.class.new(new_data)
end

#inspect_dataObject



28
29
30
31
# File 'lib/aygabtu/scope/action.rb', line 28

def inspect_data
  return super unless actions = @data[:actions]
  super.merge(action: actions.map(&:inspect).join('; '))
end

#matches_route?(route) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/aygabtu/scope/action.rb', line 11

def matches_route?(route)
  if @data[:actions]
    @data[:actions].include?(route.action)
  else
    true
  end && super
end

#segments_split_onceObject



19
20
21
22
23
24
25
26
# File 'lib/aygabtu/scope/action.rb', line 19

def segments_split_once
  return super unless Array(@data[:actions]).length > 1

  @data[:actions].map do |action|
    new_data = @data.merge(actions: [action])
    self.class.new(new_data)
  end
end