Module: MakeModelSearchable
- Defined in:
- lib/make_model_searchable.rb,
lib/make_model_searchable/version.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #get_valid_fields(fields) ⇒ Object
- #searchable_attributes(*options) ⇒ Object
- #setup_fields(options) ⇒ Object
Instance Method Details
#get_valid_fields(fields) ⇒ Object
20 21 22 23 24 |
# File 'lib/make_model_searchable.rb', line 20 def get_valid_fields(fields) column_names = self.column_names column_types = self.column_types fields.reject { |element| !column_names.include?(element) or column_types[element].type != :string } end |
#searchable_attributes(*options) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/make_model_searchable.rb', line 5 def searchable_attributes(*) = .collect{ |option| option.to_s } self.connection setup_fields() self.extend(ClassMethods) end |
#setup_fields(options) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/make_model_searchable.rb', line 12 def setup_fields() unless .present? = self.column_names end valid_fields = get_valid_fields() self.instance_variable_set(:@selected_fields, valid_fields) end |