class ApiMaker::BaseResource

Constants

CRUD

Attributes

ability[R]
args[R]
model[R]

Public Class Methods

_attributes() click to toggle source
# File lib/api_maker/base_resource.rb, line 14
def self._attributes
  ApiMaker::MemoryStorage.current.storage_for(self, :attributes)
end
_relationships() click to toggle source
# File lib/api_maker/base_resource.rb, line 51
def self._relationships
  ApiMaker::MemoryStorage.current.storage_for(self, :relationships)
end
attributes(*attributes, **args) click to toggle source
# File lib/api_maker/base_resource.rb, line 8
def self.attributes(*attributes, **args)
  attributes.each do |attribute|
    ApiMaker::MemoryStorage.current.add(self, :attributes, attribute, args)
  end
end
collection_commands(*list) click to toggle source
# File lib/api_maker/base_resource.rb, line 18
def self.collection_commands(*list)
  list.each do |collection_command|
    ApiMaker::MemoryStorage.current.add(self, :collection_commands, collection_command)
  end
end
collection_name() click to toggle source
# File lib/api_maker/base_resource.rb, line 55
def self.collection_name
  @collection_name ||= plural_name.underscore.dasherize
end
default_select() click to toggle source
# File lib/api_maker/base_resource.rb, line 59
def self.default_select
  _attributes.select do |_attribute_name, args|
    !args.fetch(:args).key?(:selected_by_default) || args.fetch(:args).fetch(:selected_by_default)
  end
end
member_commands(*list) click to toggle source
# File lib/api_maker/base_resource.rb, line 24
def self.member_commands(*list)
  list.each do |member_command|
    ApiMaker::MemoryStorage.current.add(self, :member_commands, member_command)
  end
end
model_class() click to toggle source
# File lib/api_maker/base_resource.rb, line 36
def self.model_class
  # Use the name to constantize to avoid reloading issues with Rails
  model_class_name.constantize
end
model_class=(klass) click to toggle source
# File lib/api_maker/base_resource.rb, line 30
def self.model_class=(klass)
  # Set the name to avoid reloading issues with Rails
  @model_class_name ||= klass.name
  ApiMaker::MemoryStorage.current.model_class_for(resource: self, klass: klass)
end
model_class_name() click to toggle source
# File lib/api_maker/base_resource.rb, line 41
def self.model_class_name
  @model_class_name ||= name.gsub(/Resource$/, "").gsub(/^Resources::/, "")
end
new(ability: nil, args: {}, model:) click to toggle source
# File lib/api_maker/base_resource.rb, line 73
def initialize(ability: nil, args: {}, model:)
  @ability = ability
  @args = args
  @model = model
end
plural_name() click to toggle source
# File lib/api_maker/base_resource.rb, line 65
def self.plural_name
  @plural_name ||= short_name.pluralize
end
relationships(*relationships) click to toggle source
# File lib/api_maker/base_resource.rb, line 45
def self.relationships(*relationships)
  relationships.each do |relationship|
    ApiMaker::MemoryStorage.current.add(self, :relationships, relationship)
  end
end
short_name() click to toggle source
# File lib/api_maker/base_resource.rb, line 69
def self.short_name
  @short_name ||= name.match(/\AResources::(.+)Resource\Z/)[1]
end