Class: Appydave::Tools::Configuration::Models::ChannelsConfig

Inherits:
ConfigBase
  • Object
show all
Defined in:
lib/appydave/tools/configuration/models/channels_config.rb

Overview

Channels configuration

Defined Under Namespace

Classes: ChannelInfo, ChannelLocation

Instance Attribute Summary

Attributes inherited from ConfigBase

#config_path, #data

Instance Method Summary collapse

Methods inherited from ConfigBase

#config_name, #debug, #initialize, #load, #name, #save

Constructor Details

This class inherits a constructor from Appydave::Tools::Configuration::Models::ConfigBase

Instance Method Details

#channelsObject

Retrieve a list of all channels



23
24
25
26
27
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 23

def channels
  data['channels'].map do |key, info|
    ChannelInfo.new(key, info)
  end
end

#code?(code) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 34

def code?(code)
  code = code.to_s
  data['channels'].values.any? { |info| info['code'] == code }
end

#get_channel(channel_key) ⇒ Object

Retrieve channel information by channel code (string or symbol)



10
11
12
13
14
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 10

def get_channel(channel_key)
  channel_key = channel_key.to_s
  info = data['channels'][channel_key] || default_channel_info
  ChannelInfo.new(channel_key, info)
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 29

def key?(key)
  key = key.to_s
  data['channels'].key?(key)
end


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 39

def print
  log.heading 'Channel Configuration'

  print_channels = channels.map do |channel|
    {
      key: channel.key,
      code: channel.code,
      name: channel.name,
      youtube_handle: channel.youtube_handle,
      content_projects: print_location(channel.locations.content_projects),
      video_projects: print_location(channel.locations.video_projects),
      published_projects: print_location(channel.locations.published_projects),
      abandoned_projects: print_location(channel.locations.abandoned_projects)
    }
  end

  tp print_channels, :key, :code, :name, :youtube_handle, :content_projects, :video_projects, :published_projects, :abandoned_projects
end

#set_channel(channel_key, channel_info) ⇒ Object

Set channel information



17
18
19
20
# File 'lib/appydave/tools/configuration/models/channels_config.rb', line 17

def set_channel(channel_key, channel_info)
  data['channels'] ||= {}
  data['channels'][channel_key.to_s] = channel_info.to_h
end