Module: SkullIsland::Helpers::ResourceClass
- Included in:
- Resource
- Defined in:
- lib/skull_island/helpers/resource_class.rb
Overview
Simple helper class methods for Resource
Instance Method Summary collapse
-
#determine_getter_names(original_name, opts) ⇒ Array<Symbol>
Determine a list of names to use to access a resource entity attribute.
-
#determine_setter_names(original_name, opts) ⇒ Array<Symbol>
Determine a list of names to use to set a resource entity attribute.
-
#human ⇒ String
Produce a more human-readable representation of #i18n_key.
-
#i18n_key ⇒ String
(also: #singular_route_key)
A mock internationalization key based on the class name.
-
#immutable? ⇒ Boolean
Check if a resource class is immutable.
-
#param_key ⇒ Symbol
A symbolized version of #i18n_key.
-
#properties ⇒ Hash{Symbol => Hash}
All the properties defined for this Resource class.
-
#route_key ⇒ String
A route key for building URLs.
Instance Method Details
#determine_getter_names(original_name, opts) ⇒ Array<Symbol>
Determine a list of names to use to access a resource entity attribute
11 12 13 14 15 16 17 18 19 20 21 |
# 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) ⇒ Array<Symbol>
Determine a list of names to use to set a resource entity attribute
27 28 29 30 31 |
# 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 ⇒ String
ActiveRecord ActiveModel::Name compatibility method
Produce a more human-readable representation of #i18n_key
36 37 38 |
# File 'lib/skull_island/helpers/resource_class.rb', line 36 def human i18n_key.humanize end |
#i18n_key ⇒ String Also known as: singular_route_key
ActiveRecord ActiveModel::Name compatibility method
A mock internationalization key based on the class name
48 49 50 |
# File 'lib/skull_island/helpers/resource_class.rb', line 48 def i18n_key name.split('::').last.to_underscore end |
#immutable? ⇒ Boolean
Check if a resource class is immutable
41 42 43 |
# File 'lib/skull_island/helpers/resource_class.rb', line 41 def immutable? @immutable ||= false end |
#param_key ⇒ Symbol
ActiveRecord ActiveModel::Name compatibility method
A symbolized version of #i18n_key
57 58 59 |
# File 'lib/skull_island/helpers/resource_class.rb', line 57 def param_key i18n_key.to_sym end |
#properties ⇒ Hash{Symbol => Hash}
All the properties defined for this Resource class
63 64 65 |
# File 'lib/skull_island/helpers/resource_class.rb', line 63 def properties @properties ||= {} end |
#route_key ⇒ String
ActiveRecord ActiveModel::Name compatibility method
A route key for building URLs
70 71 72 |
# File 'lib/skull_island/helpers/resource_class.rb', line 70 def route_key i18n_key.en.plural end |