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.11.1'
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/api_me.rb', line 101
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
122
123
124
125
126
127
128
|
# File 'lib/api_me.rb', line 122
def destroy
@object = find_resource
authorize_resource @object
destroy_resource!
head 204
end
|
#edit ⇒ Object
109
110
111
|
# File 'lib/api_me.rb', line 109
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.
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/api_me.rb', line 73
def index
@policy_scope = policy_scope(resource_scope)
@filter_scope = filter_scope(@policy_scope)
@sorted_scope = sort_scope(@filter_scope)
@pagination_object = paginate_scope(@sorted_scope, page_params)
render(
json: @pagination_object.results,
root: collection_root_key,
each_serializer: serializer_klass,
meta: {
page: @pagination_object.page_meta,
sort: sorting_meta(@filter_scope)
}
)
end
|
#new ⇒ Object
97
98
99
|
# File 'lib/api_me.rb', line 97
def new
render_errors(['new endpoint not supported'], 404)
end
|
#show ⇒ Object
90
91
92
93
94
95
|
# File 'lib/api_me.rb', line 90
def show
@object = find_resource
authorize_resource @object
render json: @object, root: singular_root_key, serializer: serializer_klass
end
|
#update ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'lib/api_me.rb', line 113
def update
@object = find_resource
@object.assign_attributes(object_params)
authorize_resource @object
update_resource!
head 204
end
|