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
- #import ⇒ Object
-
#initialize(name, type) ⇒ Attribute
constructor
A new instance of Attribute.
- #java_type ⇒ Object
- #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
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
38 39 40 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 38 def boolean? type.eql? "boolean" end |
#getter_prefix ⇒ Object
42 43 44 45 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 42 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 type.eql?("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 |
#import ⇒ Object
30 31 32 |
# File 'lib/vraptor-scaffold/generators/scaffold/attribute.rb', line 30 def import ImportManager.new(type).package end |
#java_type ⇒ Object
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 |
#validate ⇒ Object
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 |