Class: Foobara::Autocrud::BuildType

Inherits:
AutocrudCommand show all
Defined in:
foobara-autocrud-0.0.1/src/build_type.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from AutocrudCommand

#validate, #validate_base!

Methods inherited from Command

install!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

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

#load_entities, #load_records

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

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records

Methods included from CommandPatternImplementation::Concerns::Errors

#initialize

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

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



22
23
24
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 22

def domain
  @domain
end

#typeObject

Returns the value of attribute type.



22
23
24
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 22

def type
  @type
end

Instance Method Details

#build_typeObject



39
40
41
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 39

def build_type
  self.type = (domain || GlobalDomain).foobara_type_from_declaration(type_declaration)
end

#create_autocrud_commands_if_neededObject



57
58
59
60
61
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 57

def create_autocrud_commands_if_needed
  if type.extends?(BuiltinTypes[:entity])
    run_subcommand!(CreateCommands, entity_class: type.target_class)
  end
end

#determine_domainObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 24

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

#executeObject



13
14
15
16
17
18
19
20
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 13

def execute
  determine_domain
  build_type
  register_type_if_needed
  create_autocrud_commands_if_needed

  type
end

#register_type_if_neededObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'foobara-autocrud-0.0.1/src/build_type.rb', line 43

def register_type_if_needed
  if type.registered?
    if type_symbol && type_symbol.to_sym != type.type_symbol
      # :nocov:
      raise "Type symbol mismatch: #{type_symbol} versus #{type.type_symbol}"
      # :nocov:
    end
  else
    type.type_symbol = type_symbol
    type.foobara_parent_namespace ||= domain
    type.foobara_parent_namespace.foobara_register(type)
  end
end