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.



91
92
93
# File 'lib/active_scaffold/tableless.rb', line 91

def conditions
  @conditions
end

Instance Method Details

#except(*skips) ⇒ Object



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

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



131
132
133
# File 'lib/active_scaffold/tableless.rb', line 131

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

#find_one(id) ⇒ Object



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

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

#initialize(klass, table) ⇒ Object



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

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

#initialize_copy(other) ⇒ Object



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

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

#merge(r) ⇒ Object



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

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

#to_aObject



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

def to_a
  @klass.find_all(self)
end

#where(opts, *rest) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/active_scaffold/tableless.rb', line 103

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