Class: JekyllRecker::Social::Share Abstract

Inherits:
Object
  • Object
show all
Includes:
Mixins::Logging
Defined in:
lib/jekyll_recker/social.rb

Overview

This class is abstract.

Backend

Backend base class for social sharing backends.

Direct Known Subclasses

Slack, Twitter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Logging

#logger

Constructor Details

#initialize(site, dry: false) ⇒ Share

Returns a new instance of Share.



30
31
32
33
# File 'lib/jekyll_recker/social.rb', line 30

def initialize(site, dry: false)
  @site = site
  @dry = dry
end

Class Method Details

.share(site, dry: false) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/jekyll_recker/social.rb', line 21

def self.share(site, dry: false)
  backend = new(site, dry: dry)
  logger.info "#{backend.name} - building configuration"
  backend.configure!

  logger.info "#{backend.name} - sharing \"#{backend.latest_title}\""
  backend.post!
end

Instance Method Details

#configObject



39
40
41
# File 'lib/jekyll_recker/social.rb', line 39

def config
  @site.config.fetch('recker', {}).fetch(config_key, {})
end

#config_keyObject Also known as: name



43
44
45
# File 'lib/jekyll_recker/social.rb', line 43

def config_key
  self.class.const_get(:KEY)
end

#configure!Object

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/jekyll_recker/social.rb', line 65

def configure!
  raise NotImplementedError
end

#dry?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/jekyll_recker/social.rb', line 35

def dry?
  @dry
end

#latestObject



57
58
59
# File 'lib/jekyll_recker/social.rb', line 57

def latest
  @latest ||= @site.posts.docs.last
end

#latest_titleObject



61
62
63
# File 'lib/jekyll_recker/social.rb', line 61

def latest_title
  latest.data['title']
end

#post!Object

Raises:

  • (NotImplementedError)


69
70
71
# File 'lib/jekyll_recker/social.rb', line 69

def post!
  raise NotImplementedError
end

#post_bodyObject



48
49
50
51
52
53
54
55
# File 'lib/jekyll_recker/social.rb', line 48

def post_body
  url = File.join @site.config['url'], latest.url
  <<~BODY
    #{latest.data['date'].strftime('%A, %B %-d %Y')}
    #{latest.data['title']}
    #{url}
  BODY
end