Class: Stepford::ColumnRepresentation

Inherits:
Object
  • Object
show all
Defined in:
lib/stepford/column_representation.rb

Overview

Needed a column representation that would allow user to specify attributes that are used for sample data choice for virtual attributes e.g. if you have an object_id column in the schema, but in model you have virtual proxy attribute methods to set it like my_object_id/my_object_id= then you need a way to specify that it should set my_object_id= with a string vs. number, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ColumnRepresentation

Returns a new instance of ColumnRepresentation.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stepford/column_representation.rb', line 8

def initialize(args)
  if args.is_a?(Symbol)
    @name = args.to_sym
  elsif !(args.nil?)
    # assume initializing with column
    # see: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column
    @name = args.name
    @type = args.type
    @limit = args.limit
    @default = args.default
    @null = args.null # should be called nullable, but using what Rails/AR calls it to be easier to work with as if were a "real" AR column
    @precision = args.precision
    @scale = args.scale
  end
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def default
  @default
end

#limitObject

Returns the value of attribute limit.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def name
  @name
end

#nullObject

Returns the value of attribute null.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def null
  @null
end

#precisionObject

Returns the value of attribute precision.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def precision
  @precision
end

#scaleObject

Returns the value of attribute scale.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def scale
  @scale
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def type
  @type
end

#virtualObject

Returns the value of attribute virtual.



6
7
8
# File 'lib/stepford/column_representation.rb', line 6

def virtual
  @virtual
end

Instance Method Details

#merge_options(options) ⇒ Object



24
25
26
# File 'lib/stepford/column_representation.rb', line 24

def merge_options(options)
  options.each {|k,v|instance_variable_set("@#{k}", v)}
end