Class: Effective::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Post
- Defined in:
- app/models/effective/post.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #approve! ⇒ Object
- #approved? ⇒ Boolean
-
#duplicate ⇒ Object
Returns a duplicated post object, or throws an exception.
- #duplicate! ⇒ Object
- #event? ⇒ Boolean
- #published? ⇒ Boolean
- #send_post_submitted_to_admin! ⇒ Object
-
#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object
3.333 words/second is the default reading speed.
- #to_s ⇒ Object
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
3 4 5 |
# File 'app/models/effective/post.rb', line 3 def current_user @current_user end |
Instance Method Details
#approve! ⇒ Object
131 132 133 |
# File 'app/models/effective/post.rb', line 131 def approve! update!(draft: false) end |
#approved? ⇒ Boolean
96 97 98 |
# File 'app/models/effective/post.rb', line 96 def approved? draft == false end |
#duplicate ⇒ Object
Returns a duplicated post object, or throws an exception
115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/models/effective/post.rb', line 115 def duplicate Post.new(attributes.except('id', 'updated_at', 'created_at')).tap do |post| post.title = post.title + ' (Copy)' post.slug = post.slug + '-copy' post.draft = true regions.each do |region| post.regions.build(region.attributes.except('id', 'updated_at', 'created_at')) end end end |
#duplicate! ⇒ Object
127 128 129 |
# File 'app/models/effective/post.rb', line 127 def duplicate! duplicate.tap { |post| post.save! } end |
#event? ⇒ Boolean
100 101 102 |
# File 'app/models/effective/post.rb', line 100 def event? category == 'events' end |
#published? ⇒ Boolean
92 93 94 |
# File 'app/models/effective/post.rb', line 92 def published? !draft? && published_at.present? && published_at < Time.zone.now end |
#send_post_submitted_to_admin! ⇒ Object
109 110 111 112 |
# File 'app/models/effective/post.rb', line 109 def send_post_submitted_to_admin! deliver_method = EffectivePosts.mailer[:deliver_method] || raise('expected an EffectivePosts.deliver_method') Effective::PostsMailer.post_submitted_to_admin(to_param).send(deliver_method) end |
#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object
3.333 words/second is the default reading speed.
105 106 107 |
# File 'app/models/effective/post.rb', line 105 def time_to_read_in_seconds(reading_speed = 3.333) (regions.to_a.sum { |region| (region.content || '').scan(/\w+/).size } / reading_speed).seconds end |
#to_s ⇒ Object
88 89 90 |
# File 'app/models/effective/post.rb', line 88 def to_s title.presence || 'New Post' end |