Module: ActiveScaffold::Tableless::RelationExtension
- Included in:
- Relation
- Defined in:
- lib/active_scaffold/tableless.rb
Instance Method Summary collapse
- #conditions ⇒ Object
- #except(*skips) ⇒ Object
- #execute_simple_calculation(operation, column_name, distinct) ⇒ Object
- #exists? ⇒ Boolean
- #find_one(id) ⇒ Object
- #implicit_order_column ⇒ Object
- #initialize(klass) ⇒ Object
- #initialize_copy(other) ⇒ Object
- #merge(rel) ⇒ Object
- #where(opts, *rest) ⇒ Object (also: #where!)
Instance Method Details
#conditions ⇒ Object
93 94 95 |
# File 'lib/active_scaffold/tableless.rb', line 93 def conditions @conditions ||= [] end |
#except(*skips) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/active_scaffold/tableless.rb', line 112 def except(*skips) super.tap do |new_relation| unless new_relation.is_a?(RelationExtension) class << new_relation; include RelationExtension; end end new_relation.conditions.concat conditions unless skips.include? :where end end |
#execute_simple_calculation(operation, column_name, distinct) ⇒ Object
125 126 127 |
# File 'lib/active_scaffold/tableless.rb', line 125 def execute_simple_calculation(operation, column_name, distinct) @klass.execute_simple_calculation(self, operation, column_name, distinct) end |
#exists? ⇒ Boolean
133 134 135 |
# File 'lib/active_scaffold/tableless.rb', line 133 def exists? size.positive? end |
#find_one(id) ⇒ Object
121 122 123 |
# File 'lib/active_scaffold/tableless.rb', line 121 def find_one(id) @klass.find_one(id, self) || raise(ActiveRecord::RecordNotFound) end |
#implicit_order_column ⇒ Object
129 130 131 |
# File 'lib/active_scaffold/tableless.rb', line 129 def implicit_order_column @klass.implicit_order_column end |
#initialize(klass) ⇒ Object
83 84 85 86 |
# File 'lib/active_scaffold/tableless.rb', line 83 def initialize(klass, *) super @conditions ||= [] end |
#initialize_copy(other) ⇒ Object
88 89 90 91 |
# File 'lib/active_scaffold/tableless.rb', line 88 def initialize_copy(other) @conditions = @conditions&.dup || [] super end |
#merge(rel) ⇒ Object
106 107 108 109 110 |
# File 'lib/active_scaffold/tableless.rb', line 106 def merge(rel) super.tap do |merged| merged.conditions.concat rel.conditions unless rel.nil? || rel.is_a?(Array) end end |
#where(opts, *rest) ⇒ Object Also known as: where!
97 98 99 100 101 102 103 |
# File 'lib/active_scaffold/tableless.rb', line 97 def where(opts, *rest) if opts.present? opts = opts.with_indifferent_access if opts.is_a? Hash @conditions << (rest.empty? ? opts : [opts, *rest]) end self end |