Class: Pluto::Updater

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/pluto/cli/updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, config) ⇒ Updater

fix!!!!!: change config to text - yes/no - why? why not??

 or pass along struct
    - with hash and text and format(e.g. ini) as fields???

 - why? - we need to get handle on md5 digest/hash plus on plain text, ideally to store in db
- pass along unparsed text!! - not hash struct
    - will get saved in db plus we need to generate md5 hash
  - add filename e.g. ruby.ini|ruby.conf as opt ??
         or add config format as opt e.g. ini?


21
22
23
24
# File 'lib/pluto/cli/updater.rb', line 21

def initialize( opts, config )
  @opts    = opts
  @config  = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



26
27
28
# File 'lib/pluto/cli/updater.rb', line 26

def config
  @config
end

#optsObject (readonly)

Returns the value of attribute opts.



26
27
28
# File 'lib/pluto/cli/updater.rb', line 26

def opts
  @opts
end

Instance Method Details

#run(arg) ⇒ Object



28
29
30
31
32
# File 'lib/pluto/cli/updater.rb', line 28

def run( arg )
  arg = arg.downcase.gsub('.ini','')  # remove file extension if present

  update_for( arg )
end

#update_for(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pluto/cli/updater.rb', line 34

def update_for( name )

  ## note: allow (optional) config of site key too
  site_key = config['key'] || config['slug']
  if site_key.nil?
    ## if no key configured; use (file)name; remove -_ chars
    ##   e.g. jekyll-meta becomes jekyllmeta etc.
    site_key = name.downcase.gsub( /[\-_]/, '' )
  end

  ###################
  # step 1) update site subscriptions
  Model::Site.deep_create_or_update_from_hash!( site_key, config )

  ##############################
  # step 2) update feeds
  feed_refresher = FeedRefresher.new
  feed_refresher.refresh_feeds_for( site_key )
end