Class: SyncReadme::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_readme/config.rb

Constant Summary collapse

DEFAULT_CONFIG_FILE =
File.join(Dir.pwd, '.sync_readme.yml')
NO_CONFIGURATION_ERROR =
SyncReadme::NoConfigurationError.new("this profile has not been configured, please add it to #{DEFAULT_CONFIG_FILE}".freeze)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile, config_file = DEFAULT_CONFIG_FILE) ⇒ Config

Returns a new instance of Config.



22
23
24
25
# File 'lib/sync_readme/config.rb', line 22

def initialize(profile, config_file = DEFAULT_CONFIG_FILE)
  @raw_config = YAML.load_file(config_file)[profile]
  raise NO_CONFIGURATION_ERROR unless @raw_config
end

Class Method Details

.default(config_file = DEFAULT_CONFIG_FILE) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/sync_readme/config.rb', line 11

def self.default(config_file = DEFAULT_CONFIG_FILE)
  raise NO_CONFIGURATION_ERROR unless File.exists?(config_file)
  default = YAML.load_file(config_file)['default']
  unless default
    profiles = SyncReadme::Config.profiles(config_file)
    return profiles[0] unless profiles.empty? || profiles[1]
    raise NO_CONFIGURATION_ERROR if profiles.empty?
  end
  default
end

.profiles(config_file = DEFAULT_CONFIG_FILE) ⇒ Object



7
8
9
# File 'lib/sync_readme/config.rb', line 7

def self.profiles(config_file = DEFAULT_CONFIG_FILE)
  YAML.load_file(config_file).keys.select { |key| key != 'default' }
end

Instance Method Details

#filenameObject



47
48
49
# File 'lib/sync_readme/config.rb', line 47

def filename
  @raw_config['filename']
end

#noticeObject



35
36
37
# File 'lib/sync_readme/config.rb', line 35

def notice
  @raw_config['notice']
end

#page_idObject



43
44
45
# File 'lib/sync_readme/config.rb', line 43

def page_id
  @raw_config['page_id']
end

#passwordObject



39
40
41
# File 'lib/sync_readme/config.rb', line 39

def password
  ENV['CONFLUENCE_PASSWORD'] || @raw_config['password']
end

#strip_title?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/sync_readme/config.rb', line 51

def strip_title?
  @raw_config['strip_title'].nil? ? false : @raw_config['strip_title']
end

#syntax_highlighting?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/sync_readme/config.rb', line 55

def syntax_highlighting?
  @raw_config['syntax_highlighting'].nil? ? true : @raw_config['syntax_highlighting']
end

#urlObject



27
28
29
# File 'lib/sync_readme/config.rb', line 27

def url
  @raw_config['url']
end

#usernameObject



31
32
33
# File 'lib/sync_readme/config.rb', line 31

def username
  ENV['CONFLUENCE_USERNAME'] || @raw_config['username']
end