Class: DefaultActions

Inherits:
Object
  • Object
show all
Defined in:
lib/whales_dispatch/default_actions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ DefaultActions

Returns a new instance of DefaultActions.



3
4
5
6
7
# File 'lib/whales_dispatch/default_actions.rb', line 3

def initialize(resource)
  @resource = resource.to_s
  @resource_id = @resource.singularize + "_id"
  @actions = all
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



2
3
4
# File 'lib/whales_dispatch/default_actions.rb', line 2

def actions
  @actions
end

Instance Method Details

#createObject



27
28
29
# File 'lib/whales_dispatch/default_actions.rb', line 27

def create
  { create: { suffix: "$", method: :post } }
end

#destroyObject



39
40
41
# File 'lib/whales_dispatch/default_actions.rb', line 39

def destroy
  { destroy: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :delete } }
end

#editObject



31
32
33
# File 'lib/whales_dispatch/default_actions.rb', line 31

def edit
  { edit: { suffix: "/(?<#{@resource_id}>\\d+)/edit$", method: :get } }
end

#indexObject



15
16
17
# File 'lib/whales_dispatch/default_actions.rb', line 15

def index
  { index: { suffix: "$", method: :get } }
end

#newObject



23
24
25
# File 'lib/whales_dispatch/default_actions.rb', line 23

def new
  { new: { suffix: "/new$", method: :get } }
end

#parse_action_restrictions(restrictions_hash) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/whales_dispatch/default_actions.rb', line 9

def parse_action_restrictions(restrictions_hash)
  raise(ArgumentError) if restrictions_hash.size > 1
  send(:only, restrictions_hash[:only]) if restrictions_hash[:only]
  send(:except, restrictions_hash[:except]) if restrictions_hash[:except]
end

#showObject



19
20
21
# File 'lib/whales_dispatch/default_actions.rb', line 19

def show
  { show: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :post } }
end

#updateObject



35
36
37
# File 'lib/whales_dispatch/default_actions.rb', line 35

def update
  { update: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :put } }
end