Module: Formtastic::Inputs::Base::Naming
- Included in:
- Formtastic::Inputs::Base
- Defined in:
- lib/formtastic/inputs/base/naming.rb
Instance Method Summary collapse
- #as ⇒ Object
- #attributized_method_name ⇒ Object
- #humanized_method_name ⇒ Object
-
#input_name ⇒ Object
TODO this seems to overlap or be confused with association_primary_key.
- #sanitized_method_name ⇒ Object
- #sanitized_object_name ⇒ Object
Instance Method Details
#as ⇒ Object
6 7 8 |
# File 'lib/formtastic/inputs/base/naming.rb', line 6 def as self.class.name.split("::").last.underscore.gsub(/_input$/, '') end |
#attributized_method_name ⇒ Object
18 19 20 |
# File 'lib/formtastic/inputs/base/naming.rb', line 18 def attributized_method_name method.to_s.gsub(/_id$/, '').to_sym end |
#humanized_method_name ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/formtastic/inputs/base/naming.rb', line 22 def humanized_method_name if builder.label_str_method != :humanize # Special case where label_str_method should trump the human_attribute_name # TODO: is this actually a desired bheavior, or should we ditch label_str_method and # rely purely on :human_attribute_name. method.to_s.send(builder.label_str_method) elsif object && object.class.respond_to?(:human_attribute_name) object.class.human_attribute_name(method.to_s).send(builder.label_str_method) else method.to_s.send(builder.label_str_method) end end |
#input_name ⇒ Object
TODO this seems to overlap or be confused with association_primary_key
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/formtastic/inputs/base/naming.rb', line 36 def input_name if reflection if [:has_and_belongs_to_many, :has_many].include?(reflection.macro) "#{method.to_s.singularize}_ids" elsif reflection.respond_to? :foreign_key reflection.foreign_key else reflection.[:foreign_key] || "#{method}_id" end else method end.to_sym end |
#sanitized_method_name ⇒ Object
14 15 16 |
# File 'lib/formtastic/inputs/base/naming.rb', line 14 def sanitized_method_name @sanitized_method_name ||= method.to_s.gsub(/[\?\/\-]$/, '') end |
#sanitized_object_name ⇒ Object
10 11 12 |
# File 'lib/formtastic/inputs/base/naming.rb', line 10 def sanitized_object_name object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") end |