Module: StringScopes::ClassMethods
- Defined in:
- lib/string_scopes.rb
Instance Method Summary collapse
Instance Method Details
#create_string_scopes ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/string_scopes.rb', line 16 def create_string_scopes for column in columns if TYPES.any? { |type| column.sql_type.include?(type) } create_string_scopes_for_column(column.name) end end end |
#create_string_scopes_for_column(name) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/string_scopes.rb', line 24 def create_string_scopes_for_column(name) full_name = "#{quoted_table_name}.#{name}" scope :"#{name}_contains", lambda { |str| where("#{full_name} LIKE ?", "%#{StringScopes.escape(str)}%") } scope :"#{name}_starts_with", lambda { |str| where("#{full_name} LIKE ?", "#{StringScopes.escape(str)}%") } scope :"#{name}_ends_with", lambda { |str| where("#{full_name} LIKE ?", "%#{StringScopes.escape(str)}") } end |