Class: GistUpdater::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/gist_updater/content.rb

Overview

A content related to a gist file

Instance Method Summary collapse

Constructor Details

#initialize(user:, access_token:, gist_id:, file_path:) ⇒ Content

Returns a new instance of Content.

Parameters:

  • user (String)

    GitHub username

  • access_token (String)

    GitHub personal access token

  • gist_id (String)

    A gist id

  • file_path (String)

    A relative file path



12
13
14
15
16
17
# File 'lib/gist_updater/content.rb', line 12

def initialize(user:, access_token:, gist_id:, file_path:)
  @user         = user
  @access_token = access_token
  @gist_id      = gist_id
  @file_path    = file_path
end

Instance Method Details

#update_if_needSawyer::Resource, NilClass

Update the content if needed

Returns:

  • (Sawyer::Resource)

    an updated resource

  • (NilClass)

    isnot updated



23
24
25
26
27
28
29
30
31
32
# File 'lib/gist_updater/content.rb', line 23

def update_if_need
  if need_to_update?
    resource = update
    puts "Updated `#{file_path}` to #{resource.html_url}"
  elsif GistUpdater.debug
    puts "There is no update for `#{file_path}`."
  end

  pick_a_file(resource)
end