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
- #initialize(klass) ⇒ Object
- #initialize_copy(other) ⇒ Object
- #merge(rel) ⇒ Object
- #where(opts, *rest) ⇒ Object (also: #where!)
Instance Method Details
#conditions ⇒ Object
109 110 111 |
# File 'lib/active_scaffold/tableless.rb', line 109 def conditions @conditions ||= [] end |
#except(*skips) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/active_scaffold/tableless.rb', line 128 def except(*skips) super.tap do |new_relation| class << new_relation; include RelationExtension; end unless new_relation.is_a?(RelationExtension) new_relation.conditions.concat conditions unless skips.include? :where end end |
#execute_simple_calculation(operation, column_name, distinct) ⇒ Object
139 140 141 |
# File 'lib/active_scaffold/tableless.rb', line 139 def execute_simple_calculation(operation, column_name, distinct) model.execute_simple_calculation(self, operation, column_name, distinct) end |
#exists? ⇒ Boolean
145 146 147 |
# File 'lib/active_scaffold/tableless.rb', line 145 def exists? size.positive? end |
#find_one(id) ⇒ Object
135 136 137 |
# File 'lib/active_scaffold/tableless.rb', line 135 def find_one(id) model.find_one(id, self) || raise(ActiveRecord::RecordNotFound) end |
#initialize(klass) ⇒ Object
99 100 101 102 |
# File 'lib/active_scaffold/tableless.rb', line 99 def initialize(klass, *) super @conditions ||= [] end |
#initialize_copy(other) ⇒ Object
104 105 106 107 |
# File 'lib/active_scaffold/tableless.rb', line 104 def initialize_copy(other) @conditions = @conditions&.dup || [] super end |
#merge(rel) ⇒ Object
122 123 124 125 126 |
# File 'lib/active_scaffold/tableless.rb', line 122 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!
113 114 115 116 117 118 119 |
# File 'lib/active_scaffold/tableless.rb', line 113 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 |