Class: Arfy::MigrationBuilder::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/arfy/migration_builder/builders/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = nil) ⇒ Column

Returns a new instance of Column.



69
70
71
72
73
74
75
# File 'lib/arfy/migration_builder/builders/column.rb', line 69

def initialize(name, type=nil)
  unless type.nil?
    raise InvalidColumnTypeError, type unless valid_types.include? type
  end
  @name = name
  @type = type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



135
136
137
138
139
140
141
142
143
144
# File 'lib/arfy/migration_builder/builders/column.rb', line 135

def method_missing(method, *args)
  if is_valid_option_setter? method
    option_name = method.to_s.gsub("=", "").to_sym
    add_option(option_name, args[0])
  elsif is_valid_option_getter? method
    return option_for method
  else
    super
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



68
69
70
# File 'lib/arfy/migration_builder/builders/column.rb', line 68

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



68
69
70
# File 'lib/arfy/migration_builder/builders/column.rb', line 68

def type
  @type
end

Instance Method Details

#add_option(option_name, value = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/arfy/migration_builder/builders/column.rb', line 87

def add_option(option_name, value=nil)
  @options ||= []
  if value
    option = Option.new(option_name, value)
  else
    # seria bom conferir se é um option mesmo?
    option = option_name
  end
  @options << option
  option
end

#options_stringObject



82
83
84
85
# File 'lib/arfy/migration_builder/builders/column.rb', line 82

def options_string
  return "" if @options.nil?
  processed_options.join(", ")
end

#respond_to?(method, includes_private_methods = false) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/arfy/migration_builder/builders/column.rb', line 77

def respond_to?(method, includes_private_methods=false)
  valid_option = is_valid_option_getter?(method) || is_valid_option_setter?(method)
  return valid_option || super
end