class Cuprum::Rails::Collection
Wraps an ActiveRecord model as a Cuprum
collection.
Attributes
collection_name[R]
@return [String] The name of the collection.
member_name[R]
@return [String] the name of a collection entity.
options[R]
@return [Hash<Symbol>] additional options for the command.
record_class[R]
@return [Class] the ActiveRecord class for the collection.
Public Class Methods
new( record_class:, collection_name: nil, member_name: nil, **options )
click to toggle source
@param collection_name
[String, Symbol] The name of the collection. @param member_name
[String] The name of a collection entity. @param options [Hash<Symbol>] Additional options for the command. @param record_class
[Class] The ActiveRecord class for the collection.
Calls superclass method
# File lib/cuprum/rails/collection.rb, line 14 def initialize( record_class:, collection_name: nil, member_name: nil, **options ) super() @collection_name = resolve_collection_name(collection_name, record_class) @member_name = resolve_member_name(@collection_name, member_name) @record_class = record_class @options = options end
Public Instance Methods
query()
click to toggle source
A new Query
instance, used for querying against the collection data.
@return [Cuprum::Rails::Query] the query.
# File lib/cuprum/rails/collection.rb, line 88 def query Cuprum::Rails::Query.new(record_class) end
Private Instance Methods
command_options()
click to toggle source
# File lib/cuprum/rails/collection.rb, line 94 def command_options @command_options ||= { collection_name: collection_name, member_name: member_name, record_class: record_class, **options } end
resolve_collection_name(collection_name, record_class)
click to toggle source
# File lib/cuprum/rails/collection.rb, line 103 def resolve_collection_name(collection_name, record_class) return collection_name.to_s unless collection_name.nil? record_class.name.underscore.pluralize end
resolve_member_name(collection_name, member_name)
click to toggle source
# File lib/cuprum/rails/collection.rb, line 109 def resolve_member_name(collection_name, member_name) return member_name.to_s unless member_name.nil? collection_name.singularize end