Class: GistUpdater::Updater

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

Overview

Updates according to user configuration

Instance Method Summary collapse

Constructor Details

#initialize(options, config_class = Config) ⇒ Updater

Returns a new instance of Updater.

Parameters:

  • options (Hash)

    options generated by Thor

  • config_class (Class) (defaults to: Config)

    A Class which has configuration duty



8
9
10
11
12
13
# File 'lib/gist_updater/updater.rb', line 8

def initialize(options, config_class = Config)
  @user             = options[:user] || ENV['GISTUPDATER_USER']
  @access_token     = options[:token] || ENV['GISTUPDATER_ACCESS_TOKEN']
  @config           = config_class.new(options[:yaml])
  GistUpdater.debug = options[:debug]
end

Instance Method Details

#update(content_class = Content) ⇒ Array<Sawyer::Resource>

Update your Gist

Parameters:

  • content_class (Class) (defaults to: Content)

    A Class which has content duty

Returns:

  • (Array<Sawyer::Resource>)

    Updated resource(s)



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gist_updater/updater.rb', line 19

def update(content_class = Content)
  updated = []

  config.each do |gist_id:, file_paths:|
    file_paths.each do |file_path|
      updated << update_by_gist(gist_id, file_path, content_class)
    end
  end

  updated.compact
end