Module: Foobara::ModelAttributeHelpers::Concerns::AttributeHelpers::ClassMethods
- Defined in:
- foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb
Instance Method Summary collapse
- #foobara_attributes_for_aggregate_update(require_primary_key: true, initial: true) ⇒ Object
- #foobara_attributes_for_atom_update(require_primary_key: true) ⇒ Object
-
#foobara_attributes_for_create(includes_primary_key: false, include_private: true, include_delegates: false) ⇒ Object
TODO: we should have metadata on the entity about whether it required a primary key upon creation or not instead of an option here.
- #foobara_attributes_for_find_by ⇒ Object
- #foobara_attributes_for_update(require_primary_key: true) ⇒ Object
- #foobara_has_primary_key? ⇒ Boolean
Instance Method Details
#foobara_attributes_for_aggregate_update(require_primary_key: true, initial: true) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 64 def (require_primary_key: true, initial: true) declaration = .declaration_data declaration = Util.deep_dup(declaration) declaration.delete(:defaults) declaration.delete(:required) if initial && if require_primary_key declaration[:required] = [] else declaration = TypeDeclarations::Attributes.reject(declaration, ) end end .each_pair do |data_path, type| if type.extends?(BuiltinTypes[:entity]) target_class = type.target_class entry = (declaration, DataPath.new(data_path).path) entry.clear entry.merge!(target_class.(initial: false)) end end declaration end |
#foobara_attributes_for_atom_update(require_primary_key: true) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 92 def (require_primary_key: true) declaration = .declaration_data declaration = Util.deep_dup(declaration) declaration.delete(:defaults) if if require_primary_key declaration[:required] = [] else declaration = TypeDeclarations::Attributes.reject(declaration, ) end end # expect all associations to be expressed as primary key values # TODO: should we have a special type for encapsulating primary keys types?? .each_pair do |data_path, type| if type.extends?(BuiltinTypes[:entity]) target_class = type.target_class # TODO: do we really need declaration_data? Why cant we use the type directly? # TODO: make this work with the type directly for performance reasons. primary_key_type_declaration = target_class..declaration_data entry = (declaration, DataPath.new(data_path).path) entry.clear entry.merge!(primary_key_type_declaration) end end declaration end |
#foobara_attributes_for_create(includes_primary_key: false, include_private: true, include_delegates: false) ⇒ Object
TODO: we should have metadata on the entity about whether it required a primary key upon creation or not instead of an option here.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 34 def ( includes_primary_key: false, # usually the underlying data store creates this include_private: true, # we usually need to initialize these values to something but not always include_delegates: false # usually these are already set on the passed-in objects it delegates to ) if includes_primary_key && include_private if include_delegates || delegates.empty? return end end declaration = .declaration_data Namespace.use .created_in_namespace do unless includes_primary_key declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, ) end unless include_private declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, *private_attribute_names) end unless include_delegates declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, *delegates.keys) end Domain.current.(declaration) end end |
#foobara_attributes_for_find_by ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 123 def element_type_declarations = {} .element_types.each_pair do |attribute_name, attribute_type| element_type_declarations[attribute_name] = attribute_type.reference_or_declaration_data end handler = Domain.global..handler_for_class( TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration ) handler.desugarize( type: "::attributes", element_type_declarations: ) end |
#foobara_attributes_for_update(require_primary_key: true) ⇒ Object
28 29 30 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 28 def (require_primary_key: true) (require_primary_key:) end |
#foobara_has_primary_key? ⇒ Boolean
24 25 26 |
# File 'foobara-0.0.110/projects/model_attribute_helpers/src/attribute_helpers.rb', line 24 def respond_to?(:foobara_primary_key_attribute) end |