Module: ActiveScaffold::Tableless::RelationExtension

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

Instance Method Summary collapse

Instance Method Details

#conditionsObject



84
85
86
# File 'lib/active_scaffold/tableless.rb', line 84

def conditions
  @conditions
end

#except(*skips) ⇒ Object



112
113
114
115
116
# File 'lib/active_scaffold/tableless.rb', line 112

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



126
127
128
# File 'lib/active_scaffold/tableless.rb', line 126

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

#find_one(id) ⇒ Object



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

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

#initialize(klass, table) ⇒ Object



88
89
90
91
# File 'lib/active_scaffold/tableless.rb', line 88

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

#initialize_copy(other) ⇒ Object



93
94
95
96
# File 'lib/active_scaffold/tableless.rb', line 93

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

#merge(r) ⇒ Object



106
107
108
109
110
# File 'lib/active_scaffold/tableless.rb', line 106

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

#to_aObject



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

def to_a
  @klass.find_all(self)
end

#where(opts, *rest) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/active_scaffold/tableless.rb', line 98

def where(opts, *rest)
  unless opts.blank?
    opts = opts.with_indifferent_access if opts.is_a? Hash
    @conditions << (rest.empty? ? opts : [opts, *rest])
  end
  self
end