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.



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

def conditions
  @conditions
end

Instance Method Details

#except(*skips) ⇒ Object



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

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



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

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

#find_one(id) ⇒ Object



120
121
122
# File 'lib/active_scaffold/tableless.rb', line 120

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

#initialize(klass, table) ⇒ Object



86
87
88
89
# File 'lib/active_scaffold/tableless.rb', line 86

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

#initialize_copy(other) ⇒ Object



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

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

#merge(r) ⇒ Object



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

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

#to_aObject



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

def to_a
  @klass.find_all(self)
end

#where(opts, *rest) ⇒ Object



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

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