Class: Attribute
- Inherits:
-
Object
- Object
- Attribute
- Defined in:
- lib/vraptor-scaffold/generators/scaffold/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #getter_prefix ⇒ Object
- #html_input ⇒ Object
- #html_label ⇒ Object
-
#initialize(name, type) ⇒ Attribute
constructor
A new instance of Attribute.
- #java_type ⇒ Object
- #text? ⇒ Boolean
- #validate ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 2 def name @name end |
#type ⇒ Object
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_types ⇒ Object
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
32 33 34 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 32 def boolean? @type.eql? "boolean" end |
#getter_prefix ⇒ Object
40 41 42 43 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 40 def getter_prefix return "is" if boolean? "get" end |
#html_input ⇒ Object
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_label ⇒ Object
17 18 19 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 17 def html_label @name.underscore.humanize end |
#java_type ⇒ Object
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
36 37 38 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 36 def text? @type.eql? "text" end |
#validate ⇒ Object
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 |