Module: StringScopes::ClassMethods
- Defined in:
- lib/string_scopes.rb
Instance Method Summary collapse
Instance Method Details
#create_string_scopes ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/string_scopes.rb', line 14 def create_string_scopes for column in columns if column.sql_type.index("character") == 0 || column.sql_type.index("text") == 0 create_string_scopes_for_column(column.name) end end end |
#create_string_scopes_for_column(name) ⇒ Object
22 23 24 25 26 |
# File 'lib/string_scopes.rb', line 22 def create_string_scopes_for_column(name) scope :"#{name}_contains", lambda { |str| where("#{quoted_table_name}.#{name} LIKE ?", "%#{StringScopes.escape(str)}%") } scope :"#{name}_starts_with", lambda { |str| where("#{quoted_table_name}.#{name} LIKE ?", "#{StringScopes.escape(str)}%") } scope :"#{name}_ends_with", lambda { |str| where("#{quoted_table_name}.#{name} LIKE ?", "%#{StringScopes.escape(str)}") } end |