Sha256: 7d9809150c4cf57c4e806673cb0fa4bbf328162296851b28ca5fe4e916e8b856

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

class Attribute
  attr_accessor :name, :type

  def initialize(name, type)
    @name = name.underscore.camelize(:lower)
    @type = type.downcase
    validate
  end

  def html_input
    input = "text"
    input = "checkbox" if boolean?
    input = "textarea" if type.eql?("text")
    input
  end

  def java_type
    java = type.capitalize
    java = "boolean" if boolean?
    java = "String" if type.eql?("text")
    java
  end

  def self.valid_types
    %w(boolean double float short integer long string text)
  end

  def boolean?
    type.eql? "boolean"
  end
  
  def getter_prefix
    return "is" if boolean?
    "get"
  end

  def validate
    unless Attribute.valid_types.include?(@type)
      puts "Attribute #{@type} is not supported. The supported attributes types are: #{Attribute.valid_types.join(", ")}"
      Kernel::exit
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vraptor-scaffold-1.2.1 lib/vraptor-scaffold/generators/scaffold/attribute.rb
vraptor-scaffold-1.2.0 lib/vraptor-scaffold/generators/scaffold/attribute.rb