Class: RailsApiDoc::Controller::Param

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_api_doc/controller/param.rb

Direct Known Subclasses

Request::Param, Response::Param

Constant Summary collapse

COMMON_VALID_KEYS =

:nodoc:

[:type, :model, :desc, :id, :nested, :action_type].freeze
VALID_REQUEST_KEYS =
[:required, :enum, :value].freeze
VALID_RESPONSE_KEYS =
[:attr].freeze
VALID_KEYS =
(COMMON_VALID_KEYS + VALID_REQUEST_KEYS + VALID_RESPONSE_KEYS).freeze
HELPER_KEYS =
[:new, :is_new, :param, :name, :store].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_accessors(*accessors) ⇒ Object

redirect all keys accssors to store .type= is @store= .type is @store



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_api_doc/controller/param.rb', line 30

def self.define_accessors(*accessors)
  accessors.each do |acc|
    define_method acc do
      @store[acc]
    end

    define_method "#{acc}?" do
      @store[acc].present?
    end

    define_method "#{acc}=" do |val|
      @store[acc] = val
    end
  end
end

Instance Method Details

#add_updated_field(field) ⇒ Object



73
74
75
# File 'lib/rails_api_doc/controller/param.rb', line 73

def add_updated_field(field)
  @new.push(field) unless field.in?(@new)
end

#created?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rails_api_doc/controller/param.rb', line 65

def created?
  param&.action_type == 'create'
end

#destroyed?Boolean

these are actions applied to the params by gem user from frontend

Returns:

  • (Boolean)


61
62
63
# File 'lib/rails_api_doc/controller/param.rb', line 61

def destroyed?
  param&.action_type == 'destroy'
end

#display_nameObject

redefined in descendants



101
102
103
# File 'lib/rails_api_doc/controller/param.rb', line 101

def display_name
  @name
end

#display_specialObject

redefined in descendants



95
96
# File 'lib/rails_api_doc/controller/param.rb', line 95

def display_special
end

#display_typeObject

redefine to get desired behaviour



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rails_api_doc/controller/param.rb', line 80

def display_type
  t = if nested?
        (model || type).to_s + '(Nested)'
      else
        type.to_s
      end

  t += "(#{param.type})" if param && param.type != type

  t
end

#display_valueObject

redefined in descendants



108
109
# File 'lib/rails_api_doc/controller/param.rb', line 108

def display_value
end

#updated?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/rails_api_doc/controller/param.rb', line 69

def updated?
  param&.action_type == 'update'
end