Class: DataType::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/dsl/data_type.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Base
Pass the developer’s ActiveRecord::Base structure and we’ll decide the best structure
9
10
11
12
13
14
15
16
|
# File 'lib/dsl/data_type.rb', line 9
def initialize(options={})
@options = options
@value = options.delete(:value)
@example = options.delete(:example)
@field = options.delete(:field)
@aliases = options.delete(:was) || ::Array.new
options[:type] = options.delete(:as) if options[:as] end
|
Instance Attribute Details
Returns the value of attribute aliases.
5
6
7
|
# File 'lib/dsl/data_type.rb', line 5
def aliases
@aliases
end
|
Class Method Details
.default_mock ⇒ Object
Default mock should be overridden in derived classes
41
42
43
|
# File 'lib/dsl/data_type.rb', line 41
def self.default_mock
short_text_mock
end
|
.long_text_mock ⇒ Object
45
46
47
|
# File 'lib/dsl/data_type.rb', line 45
def self.long_text_mock
(1..3).to_a.collect { Faker::Lorem.paragraph }.join("\n")
end
|
.migrant_data_type? ⇒ Boolean
77
|
# File 'lib/dsl/data_type.rb', line 77
def self.migrant_data_type?; true; end
|
.short_text_mock ⇒ Object
49
50
51
|
# File 'lib/dsl/data_type.rb', line 49
def self.short_text_mock
Faker::Lorem.sentence
end
|
Instance Method Details
#==(compared_column) ⇒ Object
27
28
29
30
|
# File 'lib/dsl/data_type.rb', line 27
def ==(compared_column)
column[:type] == compared_column[:type]
end
|
23
24
25
|
# File 'lib/dsl/data_type.rb', line 23
def column
column_defaults.merge(@options)
end
|
#column_defaults ⇒ Object
Default is ‘ye good ol varchar(255)
19
20
21
|
# File 'lib/dsl/data_type.rb', line 19
def column_defaults
{ :type => :string }
end
|
#dangerous_migration_from?(current_structure = nil) ⇒ Boolean
73
74
75
|
# File 'lib/dsl/data_type.rb', line 73
def dangerous_migration_from?(current_structure = nil)
current_structure && (column[:type] != :text && [:string, :text].include?(current_structure[:type]) && column[:type] != current_structure[:type])
end
|
32
33
34
|
# File 'lib/dsl/data_type.rb', line 32
def mock
@value || self.class.default_mock
end
|
#serialized? ⇒ Boolean
36
37
38
|
# File 'lib/dsl/data_type.rb', line 36
def serialized?
false
end
|
#structure_changes_from(current_structure = nil) ⇒ Object
Decides if and how a column will be changed Provide the details of a previously column, or simply nil to create a new column
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/dsl/data_type.rb', line 55
def structure_changes_from(current_structure = nil)
new_structure = column
if current_structure
if new_structure[:limit] && current_structure[:limit].to_i != new_structure[:limit].to_i ||
new_structure[:type] != current_structure[:type] ||
new_structure[:default] && new_structure[:default] != current_structure[:default]
column
else
nil end
else
column
end
end
|