Class: Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/vraptor-scaffold/generators/scaffold/attribute.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Attribute

Returns a new instance of Attribute.



4
5
6
7
8
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 4

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 2

def name
  @name
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 2

def type
  @type
end

Class Method Details

.valid_typesObject



34
35
36
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 34

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

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 38

def boolean?
  type.eql? "boolean"
end

#getter_prefixObject



42
43
44
45
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 42

def getter_prefix
  return "is" if boolean?
  "get"
end

#html_inputObject



10
11
12
13
14
15
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 10

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

#html_labelObject



17
18
19
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 17

def html_label
  @name.underscore.humanize
end

#importObject



30
31
32
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 30

def import
  ImportManager.new(type).package
end

#java_typeObject



21
22
23
24
25
26
27
28
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 21

def java_type
  java = type.capitalize
  java = "boolean" if boolean?
  java = "String" if type.eql?("text")
  java = "Date" if type.eql?("date")
  java = name.camelize if type.eql?("references")
  java
end

#validateObject



47
48
49
50
51
52
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 47

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