module SkullIsland::Helpers::ResourceClass
Simple helper class methods for Resource
Public Instance Methods
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 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
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
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
Check if a resource class is immutable
# File lib/skull_island/helpers/resource_class.rb, line 41 def immutable? @immutable ||= false end
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
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
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