Class: Swagger::Api::Actions

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Model
Defined in:
lib/swagger/api/actions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



9
10
11
# File 'lib/swagger/api/actions.rb', line 9

def controller
  @controller
end

Instance Method Details

#all!Object



12
13
14
15
16
# File 'lib/swagger/api/actions.rb', line 12

def all!
  raise self.errors.full_messages unless self.valid?
  return only_actions unless only_actions.blank?
  defined_actions
end

#controller_actionsObject



22
23
24
25
# File 'lib/swagger/api/actions.rb', line 22

def controller_actions
  return [] unless controller.actions.is_a? Array
  controller.actions
end

#defined_actionsObject



18
19
20
# File 'lib/swagger/api/actions.rb', line 18

def defined_actions
  (restful_actions + controller_actions) - except_actions
end

#except_actionsObject



31
32
33
# File 'lib/swagger/api/actions.rb', line 31

def except_actions
  controller.actions.try(:except) || []
end

#only_actionsObject



27
28
29
# File 'lib/swagger/api/actions.rb', line 27

def only_actions
  controller.actions.try(:only) || []
end

#restful_actionsObject



35
36
37
# File 'lib/swagger/api/actions.rb', line 35

def restful_actions
  %w(index show create update delete)
end

#validate_actionsObject



39
40
41
42
# File 'lib/swagger/api/actions.rb', line 39

def validate_actions
  errors.add(:base, "`actions` must include at least one of #{restful_actions}") if restful_actions.blank?
  errors.add(:base, "`actions` can only include one of #{restful_actions}. #{(defined_actions - restful_actions)} are not allowed") unless (defined_actions - restful_actions).blank?
end