Class: MDWA::Generators::ModelAttribute
- Inherits:
-
Object
- Object
- MDWA::Generators::ModelAttribute
- Defined in:
- lib/mdwa/generators/model_attribute.rb
Constant Summary collapse
- STATIC_TYPES =
[:boolean, :date, :datetime, :decimal, :float, :integer, :string, :text, :time, :timestamp, :file, :password, :status]
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#reference_type ⇒ Object
Returns the value of attribute reference_type.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean
- #filter_input ⇒ Object
- #form_field ⇒ Object
- #has_and_belongs_to_many? ⇒ Boolean
- #has_many? ⇒ Boolean
- #has_one? ⇒ Boolean
-
#initialize(arg) ⇒ ModelAttribute
constructor
Sets the attributes variables Format: <name>:<type>,<model>:<reference>:<reference_type>.
- #migration_field ⇒ Object
- #nested? ⇒ Boolean
- #nested_many? ⇒ Boolean
- #nested_one? ⇒ Boolean
- #raw ⇒ Object
- #references? ⇒ Boolean
Constructor Details
#initialize(arg) ⇒ ModelAttribute
Sets the attributes variables Format: <name>:<type>,<model>:<reference>:<reference_type>
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mdwa/generators/model_attribute.rb', line 14 def initialize( arg ) # sets the variables by the string split = arg.split(':') self.name = split[0] self.reference = split[2] self.reference_type = split[3] self.type = split[1] # type is the most important, so it's the last for override reasons @raw_string = arg end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/mdwa/generators/model_attribute.rb', line 8 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/mdwa/generators/model_attribute.rb', line 8 def name @name end |
#reference ⇒ Object
Returns the value of attribute reference.
8 9 10 |
# File 'lib/mdwa/generators/model_attribute.rb', line 8 def reference @reference end |
#reference_type ⇒ Object
Returns the value of attribute reference_type.
8 9 10 |
# File 'lib/mdwa/generators/model_attribute.rb', line 8 def reference_type @reference_type end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/mdwa/generators/model_attribute.rb', line 8 def type @type end |
Instance Method Details
#belongs_to? ⇒ Boolean
108 109 110 |
# File 'lib/mdwa/generators/model_attribute.rb', line 108 def belongs_to? return (reference_type == 'belongs_to') end |
#filter_input ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mdwa/generators/model_attribute.rb', line 85 def filter_input input = [] case self.type.to_s.to_sym when :text, :string then input << "text_field_tag :#{self.name}" when :integer, :float, :decimal then input << "text_field_tag :#{self.name}, '', :onkeypress => \"mascara(this, checaNumero)\", :maxlength => 10" when :file, :password then input << 'No possible filter for file or password.' when :time then input << 'time_select' when :datetime, :timestamp, :date then input << "text_field_tag :#{self.name}_0, '', :class => :datepicker, :onkeypress => \"mascara(this, checaData)\", :maxlength => 10" input << "text_field_tag :#{self.name}_1, '', :class => :datepicker, :onkeypress => \"mascara(this, checaData)\", :maxlength => 10" when :boolean then input << "select_tag :#{self.name}, options_for_select([[t('system.yes'), 1], [t('system.no'), 0]]), :prompt => t('system.both')" when :status then input << "select_tag :#{self.name}, options_for_select(#{self.model.klass}.#{self.name}_to_select), :prompt => t('#{self.model.plural_name}.#{self.name}.prompt_select')" else input << "text_field_tag :#{self.name}" end end |
#form_field ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mdwa/generators/model_attribute.rb', line 69 def form_field @form_field ||= case self.type.to_s.to_sym when :integer then 'number_field' when :float, :decimal then 'text_field' when :file then 'file_field' when :time then 'time_select' when :datetime, :timestamp then 'datetime_select' when :date then 'text_field' when :text then 'text_area' when :boolean then 'check_box' when :password then 'password_field' else 'text_field' end end |
#has_and_belongs_to_many? ⇒ Boolean
132 133 134 |
# File 'lib/mdwa/generators/model_attribute.rb', line 132 def has_and_belongs_to_many? return (reference_type == 'has_and_belongs_and_to_many') end |
#has_many? ⇒ Boolean
112 113 114 |
# File 'lib/mdwa/generators/model_attribute.rb', line 112 def has_many? return (reference_type == 'has_many') end |
#has_one? ⇒ Boolean
128 129 130 |
# File 'lib/mdwa/generators/model_attribute.rb', line 128 def has_one? return (reference_type == 'has_one') end |
#migration_field ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mdwa/generators/model_attribute.rb', line 53 def migration_field @migration_field ||= case self.type.to_s.to_sym when :string, :password then 'string' when :boolean then 'boolean' when :date then 'date' when :datetime then 'datetime' when :decimal, :float then 'decimal' when :text then 'text' when :time then 'time' when :timestamp then 'timestamp' when :file then 'attachment' else 'integer' end end |
#nested? ⇒ Boolean
120 121 122 |
# File 'lib/mdwa/generators/model_attribute.rb', line 120 def nested? nested_many? || nested_one? end |
#nested_many? ⇒ Boolean
116 117 118 |
# File 'lib/mdwa/generators/model_attribute.rb', line 116 def nested_many? return (reference_type == 'nested_many') end |
#nested_one? ⇒ Boolean
124 125 126 |
# File 'lib/mdwa/generators/model_attribute.rb', line 124 def nested_one? return (reference_type == 'nested_one') end |
#raw ⇒ Object
26 27 28 |
# File 'lib/mdwa/generators/model_attribute.rb', line 26 def raw @raw_string end |
#references? ⇒ Boolean
136 137 138 |
# File 'lib/mdwa/generators/model_attribute.rb', line 136 def references? !STATIC_TYPES.include?(self.type.to_s.to_sym) end |