Class: Foobara::Autocrud::CreateEntity
- Inherits:
-
AutocrudCommand
- Object
- Command
- AutocrudCommand
- Foobara::Autocrud::CreateEntity
- Defined in:
- foobara-autocrud-0.0.1/src/create_entity.rb
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#desugarized_attributes_declaration ⇒ Object
Returns the value of attribute desugarized_attributes_declaration.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#type ⇒ Object
Returns the value of attribute type.
-
#type_declaration ⇒ Object
Returns the value of attribute type_declaration.
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #attributes_handler ⇒ Object
- #build_type_declaration ⇒ Object
- #create_type ⇒ Object
- #desugarize_attributes_declaration ⇒ Object
- #determine_domain ⇒ Object
- #entity_class ⇒ Object
- #execute ⇒ Object
Methods inherited from AutocrudCommand
Methods inherited from Command
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from CommandPatternImplementation::Concerns::Reflection
Methods included from CommandPatternImplementation::Concerns::DomainMappers
#domain_map, #domain_map!, #run_mapped_subcommand!
Methods included from CommandPatternImplementation::Concerns::Subcommands
#run_subcommand!, #subcommand?
Methods included from CommandPatternImplementation::Concerns::Entities
Methods included from CommandPatternImplementation::Concerns::Transactions
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Runtime
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
Methods included from CommandPatternImplementation::Concerns::Errors
Methods included from CommandPatternImplementation::Concerns::Inputs
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
Methods included from TruncatedInspect
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs
Instance Attribute Details
#desugarized_attributes_declaration ⇒ Object
Returns the value of attribute desugarized_attributes_declaration.
26 27 28 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 26 def desugarized_attributes_declaration @desugarized_attributes_declaration end |
#domain ⇒ Object
Returns the value of attribute domain.
26 27 28 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 26 def domain @domain end |
#type ⇒ Object
Returns the value of attribute type.
26 27 28 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 26 def type @type end |
#type_declaration ⇒ Object
Returns the value of attribute type_declaration.
26 27 28 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 26 def type_declaration @type_declaration end |
Instance Method Details
#attributes_handler ⇒ Object
74 75 76 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 74 def attributes_handler domain..handler_for_class(TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration) end |
#build_type_declaration ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 53 def build_type_declaration self.type_declaration = { type: :entity, attributes_declaration: desugarized_attributes_declaration, name:, primary_key: desugarized_attributes_declaration[:element_type_declarations].keys.first } if domain && domain != GlobalDomain type_declaration[:model_module] = domain end end |
#create_type ⇒ Object
66 67 68 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 66 def create_type self.type = run_subcommand!(CreateType, type_declaration:) end |
#desugarize_attributes_declaration ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 43 def desugarize_attributes_declaration self.desugarized_attributes_declaration = if attributes_declaration.is_a?(Proc) TypeDeclarations::Dsl::Attributes.to_declaration( &attributes_declaration ) else attributes_handler.desugarize(attributes_declaration) end end |
#determine_domain ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 28 def determine_domain domain = inputs[:domain] # TODO: remove global domain from here... self.domain = Domain.to_domain(domain) rescue Domain::NoSuchDomain => e if domain.is_a?(::String) || domain.is_a?(::Symbol) self.domain = Domain.create(domain) else # :nocov: raise e # :nocov: end end |
#entity_class ⇒ Object
70 71 72 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 70 def entity_class type.target_class end |
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'foobara-autocrud-0.0.1/src/create_entity.rb', line 16 def execute determine_domain desugarize_attributes_declaration build_type_declaration create_type entity_class end |