class DbSchema::Definitions::Field::Base
Attributes
default[R]
name[R]
Public Class Methods
attributes(*attr_names, **attributes_with_defaults)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 77 def attributes(*attr_names, **attributes_with_defaults) valid_attributes.push(*attr_names) attributes_with_defaults.each do |attr_name, default_value| valid_attributes.push(attr_name) default_attribute_values[attr_name] = default_value end end
default_attribute_values()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 90 def default_attribute_values @default_attribute_values ||= {} end
new(name, null: true, default: nil, **attributes)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 8 def initialize(name, null: true, default: nil, **attributes) @name = name @null = null @default = default @attributes = attributes end
register(*types)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 71 def register(*types) types.each do |type| Field.registry[type] = self end end
type()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 94 def type Field.registry.key(self) end
valid_attributes()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 86 def valid_attributes @valid_attributes ||= [] end
Public Instance Methods
array?()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 23 def array? false end
attributes()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 38 def attributes self.class.valid_attributes.reduce({}) do |hash, attr_name| if attr_value = @attributes[attr_name] hash.merge(attr_name => attr_value) elsif default_value = self.class.default_attribute_values[attr_name] hash.merge(attr_name => default_value) else hash end end end
custom?()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 27 def custom? false end
default_is_expression?()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 19 def default_is_expression? default.is_a?(Symbol) end
null?()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 15 def null? @null end
options()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 31 def options attributes.tap do |options| options[:null] = false unless null? options[:default] = default unless default.nil? end end
type()
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 50 def type self.class.type end
with_attribute(attr_name, attr_value)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 58 def with_attribute(attr_name, attr_value) Field.build(name, type, **options, attr_name => attr_value) end
with_default(new_default)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 66 def with_default(new_default) Field.build(name, type, **options, default: new_default) end
with_null(null)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 62 def with_null(null) Field.build(name, type, **options, null: null) end
with_type(new_type)
click to toggle source
# File lib/db_schema/definitions/field/base.rb, line 54 def with_type(new_type) Field.build(name, new_type, **options) end