Class: Releaf::Builders::Utilities::ResolveAttributeFieldMethodName
- Inherits:
-
Object
- Object
- Releaf::Builders::Utilities::ResolveAttributeFieldMethodName
- Includes:
- Service
- Defined in:
- app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb
Constant Summary collapse
- FIELD_TYPE_RESOLVERS =
{ string: [:image, :file, :password, :email, :link, :text], text: [:link, :richtext, :textarea], integer: [:item], datetime: [], date: [], time: [], float: [], decimal: [], boolean: [], }
Instance Method Summary collapse
- #call ⇒ Object
- #column_field_type_resolvers ⇒ Object
- #column_type ⇒ Object
- #columns_class ⇒ Object
- #email? ⇒ Boolean
- #field_type ⇒ Object
- #file? ⇒ Boolean
- #image? ⇒ Boolean
- #item? ⇒ Boolean
- #link? ⇒ Boolean
- #password? ⇒ Boolean
- #richtext? ⇒ Boolean
- #text? ⇒ Boolean
- #textarea? ⇒ Boolean
Instance Method Details
#call ⇒ Object
19 20 21 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 19 def call "releaf_#{field_type}_field" end |
#column_field_type_resolvers ⇒ Object
35 36 37 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 35 def column_field_type_resolvers FIELD_TYPE_RESOLVERS[column_type] end |
#column_type ⇒ Object
27 28 29 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 27 def column_type @column_type ||= columns_class.columns_hash[attribute_name] ? columns_class.columns_hash[attribute_name].type : :string end |
#columns_class ⇒ Object
31 32 33 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 31 def columns_class object.class end |
#email? ⇒ Boolean
51 52 53 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 51 def email? attribute_name.match(/(_email$|^email$)/).present? end |
#field_type ⇒ Object
23 24 25 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 23 def field_type column_field_type_resolvers.find{|resolver_name| send("#{resolver_name}?") == true } || column_type end |
#file? ⇒ Boolean
43 44 45 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 43 def file? attribute_name.match(/_uid$/).present? && object.respond_to?(attribute_name.sub(/_uid$/, '')) end |
#image? ⇒ Boolean
39 40 41 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 39 def image? attribute_name.match(/(thumbnail|image|photo|picture|avatar|logo|banner|icon)_uid$/).present? && file? end |
#item? ⇒ Boolean
71 72 73 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 71 def item? attribute_name.match(/_id$/).present? && object.class.reflect_on_association(attribute_name[0..-4].to_sym).present? end |
#link? ⇒ Boolean
55 56 57 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 55 def link? attribute_name.match(/(_url$|_link$|^url$|^link$)/).present? end |
#password? ⇒ Boolean
47 48 49 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 47 def password? attribute_name.match(/(password|^pin$)/).present? end |
#richtext? ⇒ Boolean
59 60 61 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 59 def richtext? attribute_name.match(/(_html$|^html$)/).present? end |
#text? ⇒ Boolean
67 68 69 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 67 def text? column_type == :string end |
#textarea? ⇒ Boolean
63 64 65 |
# File 'app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb', line 63 def textarea? column_type == :text end |