Module: Foobara::ActiveRecordType
- Defined in:
- foobara-active-record-type-0.0.14/lib/foobara/active_record_type.rb,
foobara-active-record-type-0.0.14/src/casters/hash.rb,
foobara-active-record-type-0.0.14/src/active_record_type.rb,
foobara-active-record-type-0.0.14/src/casters/primary_key.rb,
foobara-active-record-type-0.0.14/src/active_record_foobara_methods.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/hash_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/to_type_transformer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/model_class_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/primary_key_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/validate_primary_key_present.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/attributes_handler_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/validate_primary_key_is_symbol.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/active_record_base_class_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/validate_primary_key_references_attribute.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/type_declaration_extension/registered_type_declaration/desugarizers/registered_active_record_base_class_desugarizer.rb,
foobara-active-record-type-0.0.14/src/extend_active_record_type_declaration/type_declaration_extension/registered_type_declaration/desugarizers/unregistered_active_record_base_class_desugarizer.rb
Overview
TODO: I think we should have a configuration that indicates if created records can have primary keys past to them or not. That is, do primary keys get issued by the database upon insertion? Or are they generated externally and passed in? Would be nice to have programmatic clarification via explicit configuration.
Defined Under Namespace
Modules: ActiveRecordFoobaraMethods, Casters
Classes: ExtendActiveRecordTypeDeclaration
Class Method Summary
collapse
Class Method Details
.column_from_name(active_record_class, name) ⇒ Object
29
30
31
32
33
|
# File 'foobara-active-record-type-0.0.14/src/active_record_type.rb', line 29
def column_from_name(active_record_class, name)
active_record_class.columns.find do |column|
column.name == name
end
end
|
.column_name_to_foobara_type_declaration(active_record_class, name) ⇒ Object
4
5
6
7
|
# File 'foobara-active-record-type-0.0.14/src/active_record_type.rb', line 4
def column_name_to_foobara_type_declaration(active_record_class, name)
column = column_from_name(active_record_class, name)
column_to_foobara_type_declaration(column)
end
|
.column_to_foobara_type_declaration(column) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'foobara-active-record-type-0.0.14/src/active_record_type.rb', line 9
def column_to_foobara_type_declaration(column)
column_type = column.sql_type_metadata.type
type_declaration = case column_type
when :integer, :string, :datetime, :boolean
column_type
else
raise ArgumentError, "Not sure how to convert #{column_type} to a foobara type symbol"
end
if column.null
{ type: type_declaration, allow_nil: true }
else
type_declaration
end
end
|
.reset_all ⇒ Object
40
41
42
43
44
|
# File 'foobara-active-record-type-0.0.14/lib/foobara/active_record_type.rb', line 40
def reset_all
Entity::Concerns::Callbacks.reset_all
install!
end
|