Class: Effective::Classified

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/classified.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



7
8
9
# File 'app/models/effective/classified.rb', line 7

def current_user
  @current_user
end

#importingObject

Returns the value of attribute importing.



8
9
10
# File 'app/models/effective/classified.rb', line 8

def importing
  @importing
end

Instance Method Details

#approve!Object



188
189
190
# File 'app/models/effective/classified.rb', line 188

def approve!
  approved!
end

#end_on_distanceObject



138
139
140
141
# File 'app/models/effective/classified.rb', line 138

def end_on_distance
  date = Time.zone.now
  ApplicationController.helpers.distance_of_time_in_words(date + EffectiveClassifieds.max_duration, date).gsub('about', '').strip
end

#for_jsonObject



161
162
163
# File 'app/models/effective/classified.rb', line 161

def for_json
  { id: id, title: title, body: body.to_s, created_at: created_at, updated_at: updated_at }
end

#published?Boolean

Returns:

  • (Boolean)


169
170
171
172
173
174
175
# File 'app/models/effective/classified.rb', line 169

def published?
  return false unless approved?
  return false if archived?
  return false if start_on.blank? || (Time.zone.now < start_on)
  return false if end_on.present? && (Time.zone.now >= end_on)
  true
end

#purchasable_nameObject



165
166
167
# File 'app/models/effective/classified.rb', line 165

def purchasable_name
  "#{category} - #{title}"
end

#submit!Object



177
178
179
180
181
182
183
184
185
186
# File 'app/models/effective/classified.rb', line 177

def submit!
  
  approve! if EffectiveClassifieds.auto_approve

  after_commit do
    EffectiveClassifieds.send_email(:classified_submitted, self)
  end

  true
end

#to_sObject



157
158
159
# File 'app/models/effective/classified.rb', line 157

def to_s
  title.presence || model_name.human
end

#unapprove!Object



192
193
194
# File 'app/models/effective/classified.rb', line 192

def unapprove!
  unapproved!
end