Module: AutoDefineScope::ActiveRecordExtension
- Defined in:
- lib/auto_define_scope/active_record_extension.rb
Constant Summary collapse
- OPERATE_SQL =
{ search: " ilike ?", with: " = ?" }
Instance Attribute Summary collapse
-
#auto_define_scopes ⇒ Object
Returns the value of attribute auto_define_scopes.
Instance Method Summary collapse
- #add_scope(scope_name, lmd) ⇒ Object
- #scopes(options = { search: [], with: [] }) ⇒ Object
-
#search_columns(*columns) ⇒ Object
For example, CustomerAgentHistory include this columns is a array like [“status”, “p_way”, [“code”, “name”, agent: :province_id]].
- #with_columns(*columns) ⇒ Object
Instance Attribute Details
#auto_define_scopes ⇒ Object
Returns the value of attribute auto_define_scopes.
4 5 6 |
# File 'lib/auto_define_scope/active_record_extension.rb', line 4 def auto_define_scopes @auto_define_scopes end |
Instance Method Details
#add_scope(scope_name, lmd) ⇒ Object
22 23 24 25 26 |
# File 'lib/auto_define_scope/active_record_extension.rb', line 22 def add_scope scope_name, lmd scope scope_name, lmd @auto_define_scopes ||= [] @auto_define_scopes << scope_name end |
#scopes(options = { search: [], with: [] }) ⇒ Object
16 17 18 19 20 |
# File 'lib/auto_define_scope/active_record_extension.rb', line 16 def scopes = { search: [], with: [] } search_columns [:search] with_columns [:with] filterrific available_filters: @auto_define_scopes if @auto_define_scopes.present? end |
#search_columns(*columns) ⇒ Object
For example, CustomerAgentHistory include this columns is a array like [“status”, “p_way”, [“code”, “name”, agent: :province_id]]
8 9 10 |
# File 'lib/auto_define_scope/active_record_extension.rb', line 8 def search_columns(*columns) generate_cope columns, :search end |
#with_columns(*columns) ⇒ Object
12 13 14 |
# File 'lib/auto_define_scope/active_record_extension.rb', line 12 def with_columns(*columns) generate_cope columns, :with end |