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
129 130 131 |
# File 'lib/active_scaffold/tableless.rb', line 129 def conditions @conditions ||= [] end |
#except(*skips) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/active_scaffold/tableless.rb', line 148 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
161 162 163 |
# File 'lib/active_scaffold/tableless.rb', line 161 def execute_simple_calculation(operation, column_name, distinct) @klass.execute_simple_calculation(self, operation, column_name, distinct) end |
#exists? ⇒ Boolean
169 170 171 |
# File 'lib/active_scaffold/tableless.rb', line 169 def exists? size.positive? end |
#find_one(id) ⇒ Object
157 158 159 |
# File 'lib/active_scaffold/tableless.rb', line 157 def find_one(id) @klass.find_one(id, self) || raise(ActiveRecord::RecordNotFound) end |
#implicit_order_column ⇒ Object
165 166 167 |
# File 'lib/active_scaffold/tableless.rb', line 165 def implicit_order_column @klass.implicit_order_column end |
#initialize(klass) ⇒ Object
119 120 121 122 |
# File 'lib/active_scaffold/tableless.rb', line 119 def initialize(klass, *) super @conditions ||= [] end |
#initialize_copy(other) ⇒ Object
124 125 126 127 |
# File 'lib/active_scaffold/tableless.rb', line 124 def initialize_copy(other) @conditions = @conditions&.dup || [] super end |
#merge(rel) ⇒ Object
142 143 144 145 146 |
# File 'lib/active_scaffold/tableless.rb', line 142 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!
133 134 135 136 137 138 139 |
# File 'lib/active_scaffold/tableless.rb', line 133 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 |