Module: DryCrudJsonapi

Extended by:
ActiveSupport::Concern
Defined in:
lib/dry_crud_jsonapi.rb,
lib/dry_crud_jsonapi/engine.rb,
lib/dry_crud_jsonapi/version.rb,
app/domain/dry_crud_jsonapi/pager.rb,
app/domain/dry_crud_jsonapi/serializer.rb

Defined Under Namespace

Modules: ClassMethods, Prepends Classes: Engine, Pager, Serializer

Constant Summary collapse

VERSION =
'0.1.1'

Instance Method Summary collapse

Instance Method Details

#jsonapi_classObject



32
33
34
35
36
# File 'lib/dry_crud_jsonapi.rb', line 32

def jsonapi_class
  @jsonapi_class ||= Hash.new do |hash, class_name|
    hash[class_name] = model_serializer || Serializer.new(class_name).build
  end
end

#jsonapi_exposeObject



38
39
40
# File 'lib/dry_crud_jsonapi.rb', line 38

def jsonapi_expose
  { controller: self, current_user: current_user }
end

#jsonapi_pagination(resources) ⇒ Object



27
28
29
30
# File 'lib/dry_crud_jsonapi.rb', line 27

def jsonapi_pagination(resources)
  return unless action_name == 'index' && resources.present?
  Pager.new(resources, model_class, params).render
end

#rescued_polymorphic_path(*objects) ⇒ Object



42
43
44
# File 'lib/dry_crud_jsonapi.rb', line 42

def rescued_polymorphic_path(*objects)
  polymorphic_path(*objects) rescue nil
end