Module: ApiMe
- Extended by:
- ActiveSupport::Concern
- Includes:
- Pundit
- Defined in:
- lib/api_me.rb,
lib/api_me/model.rb,
lib/api_me/engine.rb,
lib/api_me/sorting.rb,
lib/api_me/version.rb,
lib/api_me/pagination.rb,
lib/api_me/base_filter.rb,
lib/generators/api_me/install_generator.rb,
lib/generators/api_me/filter/filter_generator.rb,
lib/generators/api_me/policy/policy_generator.rb,
lib/generators/api_me/resource/resource_generator.rb,
lib/generators/api_me/controller/controller_generator.rb
Defined Under Namespace
Modules: ClassMethods, Generators
Classes: BaseFilter, Engine, Model, Pagination, Sorting
Constant Summary
collapse
- VERSION =
'0.10.7'
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
99
100
101
102
103
104
105
|
# File 'lib/api_me.rb', line 99
def create
@object = build_resource
authorize_resource @object
create_resource!
render status: 201, json: @object, root: singular_root_key, serializer: serializer_klass
end
|
#destroy ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/api_me.rb', line 120
def destroy
@object = find_resource
authorize_resource @object
destroy_resource!
head 204
end
|
#edit ⇒ Object
107
108
109
|
# File 'lib/api_me.rb', line 107
def edit
render_errors(['edit endpoint not supported'], 404)
end
|
#index ⇒ Object
Currently merge params in filters hash to support common use case of filtering ids using the top level ids array param. Would eventually like to move to support the jsonapi.org standard closer.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/api_me.rb', line 71
def index
@policy_scope = policy_scope(resource_scope)
@filter_scope = filter_scope(@policy_scope)
@sorted_scope = sort_scope(@filter_scope)
= paginate_scope(@sorted_scope, page_params)
render(
json: .results,
root: collection_root_key,
each_serializer: serializer_klass,
meta: {
page: .page_meta,
sort: sorting_meta(@filter_scope)
}
)
end
|
#new ⇒ Object
95
96
97
|
# File 'lib/api_me.rb', line 95
def new
render_errors(['new endpoint not supported'], 404)
end
|
#show ⇒ Object
88
89
90
91
92
93
|
# File 'lib/api_me.rb', line 88
def show
@object = find_resource
authorize_resource @object
render json: @object, root: singular_root_key, serializer: serializer_klass
end
|
#update ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/api_me.rb', line 111
def update
@object = find_resource
@object.assign_attributes(object_params)
authorize_resource @object
update_resource!
head 204
end
|