module SkullIsland::Helpers::ResourceClass

Simple helper class methods for Resource

Public Instance Methods

determine_getter_names(original_name, opts) click to toggle source

Determine a list of names to use to access a resource entity attribute @param original_name [String,Symbol] the name of the underlying attribute @param opts [Hash] property options as defined in a {Resource} subclass @return [Array<Symbol>] the list of names

# File lib/skull_island/helpers/resource_class.rb, line 11
def determine_getter_names(original_name, opts)
  names = []
  names << original_name
  names << "#{original_name}?" if opts[:type] == :boolean
  if opts[:as]
    Array(opts[:as]).each do |new_name|
      names << (opts[:type] == :boolean ? "#{new_name}?" : new_name)
    end
  end
  names.map(&:to_sym).uniq
end
determine_setter_names(original_name, opts) click to toggle source

Determine a list of names to use to set a resource entity attribute @param original_name [String,Symbol] the name of the underlying attribute @param opts [Hash] property options as defined in a {Resource} subclass @return [Array<Symbol>] the list of names

# File lib/skull_island/helpers/resource_class.rb, line 27
def determine_setter_names(original_name, opts)
  names = ["#{original_name}="]
  names.concat(Array(opts[:as]).map { |new_name| "#{new_name}=" }) if opts[:as]
  names.map(&:to_sym).uniq
end
human() click to toggle source

Produce a more human-readable representation of {#i18n_key} @note ActiveRecord ActiveModel::Name compatibility method @return [String]

# File lib/skull_island/helpers/resource_class.rb, line 36
def human
  i18n_key.humanize
end
i18n_key() click to toggle source

A mock internationalization key based on the class name @note ActiveRecord ActiveModel::Name compatibility method @return [String]

# File lib/skull_island/helpers/resource_class.rb, line 48
def i18n_key
  name.split('::').last.to_underscore
end
Also aliased as: singular_route_key
immutable?() click to toggle source

Check if a resource class is immutable

# File lib/skull_island/helpers/resource_class.rb, line 41
def immutable?
  @immutable ||= false
end
param_key() click to toggle source

A symbolized version of {#i18n_key} @note ActiveRecord ActiveModel::Name compatibility method @return [Symbol]

# File lib/skull_island/helpers/resource_class.rb, line 57
def param_key
  i18n_key.to_sym
end
properties() click to toggle source

All the properties defined for this Resource class @return [Hash{Symbol => Hash}]

# File lib/skull_island/helpers/resource_class.rb, line 63
def properties
  @properties ||= {}
end
route_key() click to toggle source

A route key for building URLs @note ActiveRecord ActiveModel::Name compatibility method @return [String]

# File lib/skull_island/helpers/resource_class.rb, line 70
def route_key
  i18n_key.en.plural
end
singular_route_key()
Alias for: i18n_key