Module: ActionDispatch::Routing::Mapper::Resources

Defined in:
lib/lunar_shell/core_ext/action_dispatch.rb

Instance Method Summary collapse

Instance Method Details

#resource(*resources, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lunar_shell/core_ext/action_dispatch.rb', line 5

def resource(*resources, &block)
  options = resources.extract_options!.dup

  options[:controller] = resources.first if satellite?

  if apply_common_behavior_for(:resource, resources, options, &block)
    return self
  end

  resource_scope(:resource, SingletonResource.new(resources.pop, options)) do
    yield if block_given?

    concerns(options[:concerns]) if options[:concerns]

    collection do
      post :create if parent_resource.actions.include?(:create)
      post :run if satellite?
    end

    new do
      get :new
    end if parent_resource.actions.include?(:new)

    set_member_mappings_for_resource
  end

  self
end

#resources(*resources, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lunar_shell/core_ext/action_dispatch.rb', line 34

def resources(*resources, &block)
  options = resources.extract_options!.dup

  options[:controller] = resources.first if satellite?

  if apply_common_behavior_for(:resources, resources, options, &block)
    return self
  end

  resource_scope(:resources, Resource.new(resources.pop, options)) do
    yield if block_given?

    concerns(options[:concerns]) if options[:concerns]

    collection do
      get  :index if parent_resource.actions.include?(:index)
      post :create if parent_resource.actions.include?(:create)
      post :run if satellite?
    end

    new do
      get :new
    end if parent_resource.actions.include?(:new)

    set_member_mappings_for_resource
  end

  self
end

#satellite?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/lunar_shell/core_ext/action_dispatch.rb', line 64

def satellite?
  @scope[:as] == 'satellites'
end