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



28
29
30
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 28

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

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 32

def boolean?
  @type.eql? "boolean"
end

#getter_prefixObject



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

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 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

#java_typeObject



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

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

#text?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 36

def text?
    @type.eql? "text"
end

#validateObject



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

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