Class: Cuprum::Rails::Command
- Inherits:
-
Collections::Command
- Object
- Collections::Command
- Cuprum::Rails::Command
- Defined in:
- lib/cuprum/rails/command.rb
Overview
Abstract base class for Rails collection commands.
Direct Known Subclasses
Cuprum::Rails::Commands::AssignOne, Cuprum::Rails::Commands::BuildOne, Cuprum::Rails::Commands::DestroyOne, Cuprum::Rails::Commands::FindMany, Cuprum::Rails::Commands::FindMatching, Cuprum::Rails::Commands::FindOne, Cuprum::Rails::Commands::InsertOne, Cuprum::Rails::Commands::UpdateOne, Cuprum::Rails::Commands::ValidateOne
Instance Attribute Summary collapse
-
#collection_name ⇒ String
readonly
The name of the collection.
-
#member_name ⇒ String
readonly
The name of a collection entity.
-
#options ⇒ Hash<Symbol>
readonly
Additional options for the command.
-
#record_class ⇒ Class
readonly
The ActiveRecord class for the collection.
Class Method Summary collapse
-
.subclass(**default_options) ⇒ Object
Creates a subclass with the given parameters applied to the constructor.
Instance Method Summary collapse
-
#initialize(record_class:, collection_name: nil, member_name: nil, **options) ⇒ Command
constructor
A new instance of Command.
-
#primary_key_name ⇒ Symbol
The name of the primary key attribute.
-
#primary_key_type ⇒ Class
The type of the primary key attribute.
Constructor Details
#initialize(record_class:, collection_name: nil, member_name: nil, **options) ⇒ Command
Returns a new instance of Command.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cuprum/rails/command.rb', line 23 def initialize( record_class:, collection_name: nil, member_name: nil, ** ) super() @collection_name = resolve_collection_name(collection_name, record_class) @member_name = resolve_member_name(@collection_name, member_name) @record_class = record_class @options = end |
Instance Attribute Details
#collection_name ⇒ String (readonly)
Returns The name of the collection.
38 39 40 |
# File 'lib/cuprum/rails/command.rb', line 38 def collection_name @collection_name end |
#member_name ⇒ String (readonly)
Returns the name of a collection entity.
41 42 43 |
# File 'lib/cuprum/rails/command.rb', line 41 def member_name @member_name end |
#options ⇒ Hash<Symbol> (readonly)
Returns additional options for the command.
44 45 46 |
# File 'lib/cuprum/rails/command.rb', line 44 def @options end |
#record_class ⇒ Class (readonly)
Returns the ActiveRecord class for the collection.
47 48 49 |
# File 'lib/cuprum/rails/command.rb', line 47 def record_class @record_class end |
Class Method Details
.subclass(**default_options) ⇒ Object
Creates a subclass with the given parameters applied to the constructor.
11 12 13 14 15 16 17 |
# File 'lib/cuprum/rails/command.rb', line 11 def self.subclass(**) Class.new(self) do define_method(:initialize) do |**| super(**.merge()) end end end |
Instance Method Details
#primary_key_name ⇒ Symbol
Returns the name of the primary key attribute.
50 51 52 |
# File 'lib/cuprum/rails/command.rb', line 50 def primary_key_name @primary_key_name ||= record_class.primary_key end |
#primary_key_type ⇒ Class
Returns the type of the primary key attribute.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cuprum/rails/command.rb', line 55 def primary_key_type @primary_key_type ||= case primary_key_column_type when :integer Integer when :uuid String else # :nocov: raise "unknown primary key column type :#{primary_key_column_type}" # :nocov: end end |