Module: Bhf::ActiveRecord::Base::ClassMethods
- Defined in:
- lib/bhf/active_record/base.rb
Instance Method Summary collapse
- #bhf_attribute_method?(column_name) ⇒ Boolean
- #bhf_default_search(search_params) ⇒ Object
- #bhf_embedded? ⇒ Boolean
- #bhf_primary_key ⇒ Object
Instance Method Details
#bhf_attribute_method?(column_name) ⇒ Boolean
44 45 46 |
# File 'lib/bhf/active_record/base.rb', line 44 def bhf_attribute_method?(column_name) column_names.include?(column_name) end |
#bhf_default_search(search_params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bhf/active_record/base.rb', line 26 def bhf_default_search(search_params) return where([]) if (search_term = search_params['text']).blank? where_statement = [] columns_hash.each_pair do |name, props| is_number = search_term.to_i.to_s == search_term || search_term.to_f.to_s == search_term if props.type == :string || props.type == :text where_statement << "LOWER(#{name}) LIKE LOWER('%#{search_term}%')" elsif props.type == :integer && is_number where_statement << "#{name} = #{search_term.to_i}" elsif props.type == :float && is_number where_statement << "#{name} = #{search_term.to_f}" end end where(where_statement.join(' OR ')) end |
#bhf_embedded? ⇒ Boolean
52 53 54 |
# File 'lib/bhf/active_record/base.rb', line 52 def false end |
#bhf_primary_key ⇒ Object
48 49 50 |
# File 'lib/bhf/active_record/base.rb', line 48 def bhf_primary_key primary_key end |