Class: ModelColumn

Inherits:
Object show all
Defined in:
lib/clevic/model_column.rb

Overview

Field metadata class. Includes information for type, reflections etc.

Also, it eases the migration from AR to Sequel, which returns metadata as a hash instead of a class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hash) ⇒ ModelColumn

Returns a new instance of ModelColumn.



62
63
64
65
66
67
68
69
70
# File 'lib/clevic/model_column.rb', line 62

def initialize( name, hash )
  @hash = hash
  @hash.each do |key,value|
    send( "#{key}=", value )
  end

  # must be after hash so it takes precedence
  @name = name
end

Instance Attribute Details

#after_addObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def after_add
  @after_add
end

#after_loadObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def after_load
  @after_load
end

#after_removeObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def after_remove
  @after_remove
end

#after_setObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def after_set
  @after_set
end

#allow_nullObject

these are from Sequel::Model.columns_hash



25
26
27
# File 'lib/clevic/model_column.rb', line 25

def allow_null
  @allow_null
end

#associationObject

added by us



59
60
61
# File 'lib/clevic/model_column.rb', line 59

def association
  @association
end

#before_addObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def before_add
  @before_add
end

#before_removeObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def before_remove
  @before_remove
end

#before_setObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def before_set
  @before_set
end

#blockObject

new in sequel 3.25.0



37
38
39
# File 'lib/clevic/model_column.rb', line 37

def block
  @block
end

#cacheObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def cache
  @cache
end

#cartesian_product_numberObject

For Sequel many_to_many



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def cartesian_product_number
  @cartesian_product_number
end

#classObject

TODO not sure where these are from



34
35
36
# File 'lib/clevic/model_column.rb', line 34

def class
  @class
end

#class_nameObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def class_name
  @class_name
end

#conditionsObject

TODO not sure where these are from



34
35
36
# File 'lib/clevic/model_column.rb', line 34

def conditions
  @conditions
end

#datasetObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def dataset
  @dataset
end

#db_typeObject

these are from Sequel::Model.columns_hash



25
26
27
# File 'lib/clevic/model_column.rb', line 25

def db_type
  @db_type
end

#defaultObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def default
  @default
end

#eager_blockObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def eager_block
  @eager_block
end

#eager_grapherObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def eager_grapher
  @eager_grapher
end

#eager_loaderObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def eager_loader
  @eager_loader
end

#extendObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def extend
  @extend
end

#graph_alias_baseObject

new in sequel 3.30.0



40
41
42
# File 'lib/clevic/model_column.rb', line 40

def graph_alias_base
  @graph_alias_base
end

#graph_conditionsObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def graph_conditions
  @graph_conditions
end

#graph_join_table_conditionsObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def graph_join_table_conditions
  @graph_join_table_conditions
end

#graph_join_table_join_typeObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def graph_join_table_join_type
  @graph_join_table_join_type
end

#graph_join_typeObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def graph_join_type
  @graph_join_type
end

#join_tableObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def join_table
  @join_table
end

#keyObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def key
  @key
end

#keysObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def keys
  @keys
end

#left_keyObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def left_key
  @left_key
end

#left_key_aliasObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def left_key_alias
  @left_key_alias
end

#left_keysObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def left_keys
  @left_keys
end

#left_primary_keyObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def left_primary_key
  @left_primary_key
end

#left_primary_keysObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def left_primary_keys
  @left_primary_keys
end

#limitObject

if it’s not here, it’s probably from Sequel, so figure it out from the db_type



16
17
18
19
20
21
22
# File 'lib/clevic/model_column.rb', line 16

def limit
  unless @limit
    db_type =~ /\((\d+)\)/
    @limit = $1.to_i
  end
  @limit
end

#metaObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def meta
  @meta
end

#modelObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def model
  @model
end

#nameObject

sequel::Model.reflections



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def name
  @name
end

#orderObject

TODO not sure where these are from



34
35
36
# File 'lib/clevic/model_column.rb', line 34

def order
  @order
end

#order_eager_graphObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def order_eager_graph
  @order_eager_graph
end

#orig_optsObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def orig_opts
  @orig_opts
end

#precisionObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def precision
  @precision
end

#primaryObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def primary
  @primary
end

#primary_keyObject

these are from Sequel::Model.columns_hash



25
26
27
# File 'lib/clevic/model_column.rb', line 25

def primary_key
  @primary_key
end

#primary_keysObject

for many_to_one targets



31
32
33
# File 'lib/clevic/model_column.rb', line 31

def primary_keys
  @primary_keys
end

#qualified_keyObject

Returns the value of attribute qualified_key.



41
42
43
# File 'lib/clevic/model_column.rb', line 41

def qualified_key
  @qualified_key
end

#reciprocalObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def reciprocal
  @reciprocal
end

#reciprocal_typeObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def reciprocal_type
  @reciprocal_type
end

#right_keyObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def right_key
  @right_key
end

#right_keysObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def right_keys
  @right_keys
end

#ruby_defaultObject

these are from Sequel::Model.columns_hash



25
26
27
# File 'lib/clevic/model_column.rb', line 25

def ruby_default
  @ruby_default
end

#scaleObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def scale
  @scale
end

#sql_typeObject

these are from AR



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def sql_type
  @sql_type
end

#typeObject

sequel::Model.reflections



10
11
12
# File 'lib/clevic/model_column.rb', line 10

def type
  @type
end

#uses_composite_keysObject

sequel::Model.reflections



28
29
30
# File 'lib/clevic/model_column.rb', line 28

def uses_composite_keys
  @uses_composite_keys
end

#uses_left_composite_keysObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def uses_left_composite_keys
  @uses_left_composite_keys
end

#uses_right_composite_keysObject

For Sequel many_to_many



44
45
46
# File 'lib/clevic/model_column.rb', line 44

def uses_right_composite_keys
  @uses_right_composite_keys
end

Instance Method Details

#association?Boolean

Returns:

  • (Boolean)


60
# File 'lib/clevic/model_column.rb', line 60

def association?; association; end


76
77
78
# File 'lib/clevic/model_column.rb', line 76

def related_class
  @related_class ||= eval class_name
end