Module: ActiveScaffold::Tableless::RelationExtension

Included in:
Relation
Defined in:
lib/active_scaffold/tableless.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions


115
116
117
# File 'lib/active_scaffold/tableless.rb', line 115

def conditions
  @conditions
end

Instance Method Details

#except(*skips) ⇒ Object


141
142
143
144
145
# File 'lib/active_scaffold/tableless.rb', line 141

def except(*skips)
  super.tap do |new_relation|
    new_relation.conditions = conditions unless skips.include? :where
  end
end

#execute_simple_calculation(operation, column_name, distinct) ⇒ Object


155
156
157
# File 'lib/active_scaffold/tableless.rb', line 155

def execute_simple_calculation(operation, column_name, distinct)
  @klass.execute_simple_calculation(self, operation, column_name, distinct)
end

#exists?Boolean

Returns:

  • (Boolean)

163
164
165
# File 'lib/active_scaffold/tableless.rb', line 163

def exists?
  limit(1).to_a.present?
end

#find_one(id) ⇒ Object


151
152
153
# File 'lib/active_scaffold/tableless.rb', line 151

def find_one(id)
  @klass.find_one(id, self) || raise(ActiveRecord::RecordNotFound)
end

#implicit_order_columnObject


159
160
161
# File 'lib/active_scaffold/tableless.rb', line 159

def implicit_order_column
  @klass.implicit_order_column
end

#initialize(klass) ⇒ Object


117
118
119
120
# File 'lib/active_scaffold/tableless.rb', line 117

def initialize(klass, *)
  super
  @conditions ||= []
end

#initialize_copy(other) ⇒ Object


122
123
124
125
# File 'lib/active_scaffold/tableless.rb', line 122

def initialize_copy(other)
  @conditions = @conditions&.dup || []
  super
end

#merge(rel) ⇒ Object


135
136
137
138
139
# File 'lib/active_scaffold/tableless.rb', line 135

def merge(rel)
  super.tap do |merged|
    merged.conditions.concat rel.conditions unless rel.nil? || rel.is_a?(Array)
  end
end

#to_aObject


147
148
149
# File 'lib/active_scaffold/tableless.rb', line 147

def to_a
  @klass.find_all(self)
end

#where(opts, *rest) ⇒ Object


127
128
129
130
131
132
133
# File 'lib/active_scaffold/tableless.rb', line 127

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