Class: Rails::Generator::GeneratedAttribute
- Inherits:
-
Object
- Object
- Rails::Generator::GeneratedAttribute
- Defined in:
- lib/migratory/generated_attribute.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#is_indexed ⇒ Object
Returns the value of attribute is_indexed.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#scale ⇒ Object
Returns the value of attribute scale.
Instance Method Summary collapse
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
4 5 6 |
# File 'lib/migratory/generated_attribute.rb', line 4 def default @default end |
#is_indexed ⇒ Object
Returns the value of attribute is_indexed.
4 5 6 |
# File 'lib/migratory/generated_attribute.rb', line 4 def is_indexed @is_indexed end |
#limit ⇒ Object
Returns the value of attribute limit.
4 5 6 |
# File 'lib/migratory/generated_attribute.rb', line 4 def limit @limit end |
#precision ⇒ Object
Returns the value of attribute precision.
4 5 6 |
# File 'lib/migratory/generated_attribute.rb', line 4 def precision @precision end |
#scale ⇒ Object
Returns the value of attribute scale.
4 5 6 |
# File 'lib/migratory/generated_attribute.rb', line 4 def scale @scale end |
Instance Method Details
#initialize_with_migratory(name, type, default = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/migratory/generated_attribute.rb', line 6 def initialize_with_migratory(name, type, default = nil) @default = default @is_indexed = (name =~ /^\*/) && true if type =~ /\[.*?\]/ details = type.match(/\[(.*?)\]/)[1] if details =~ /,/ @precision, @scale = details.split(/,/).map(&:to_i) else case type.gsub(/\[.*?\]/, '').to_sym when :string, :text, :binary, :integer then @limit = details.to_i when :decimal, :float then @precision = details.to_i end end end initialize_without_migratory(name.gsub(/^\*/, ''), type.gsub(/\[.*?\]/, '')) end |
#options ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/migratory/generated_attribute.rb', line 23 def = '' << ", :limit => #{@limit}" if @limit << ", :precision => #{@precision}" if @precision << ", :scale => #{@scale}" if @scale if @default if @default == '' << ", :default => nil" else << case @type when :string, :text, :date, :datetime, :time, :timestamp then ', :default => "'+@default+'"' else ", :default => #{@default}" end end end end |