Module: LazyRecord::BaseModule::ClassMethods

Defined in:
lib/lazy_record/base_module.rb

Overview

Class methods provided to all LazyRecord classes

Instance Method Summary collapse

Instance Method Details

#allObject



125
126
127
# File 'lib/lazy_record/base_module.rb', line 125

def all
  @all ||= Relation.new(model: self)
end

#attr_readersObject



121
122
123
# File 'lib/lazy_record/base_module.rb', line 121

def attr_readers
  @attr_readers ||= []
end

#countObject



129
130
131
# File 'lib/lazy_record/base_module.rb', line 129

def count
  all.count
end

#destroy_allObject



145
146
147
# File 'lib/lazy_record/base_module.rb', line 145

def destroy_all
  all.send(:clear)
end

#firstObject



133
134
135
# File 'lib/lazy_record/base_module.rb', line 133

def first
  all.first
end

#lastObject



137
138
139
# File 'lib/lazy_record/base_module.rb', line 137

def last
  all.last
end

#public_attr_readersObject



115
116
117
118
119
# File 'lib/lazy_record/base_module.rb', line 115

def public_attr_readers
  @public_attr_readers ||= attr_readers.reject do |reader|
    private_method_defined?(reader) || protected_method_defined?(reader)
  end
end

#where(condition = nil, &block) ⇒ Object



141
142
143
# File 'lib/lazy_record/base_module.rb', line 141

def where(condition = nil, &block)
  all.where(condition, &block)
end