Class: Rabbit::AuthorConfiguration

Inherits:
Object
  • Object
show all
Includes:
GetText, PathManipulatable
Defined in:
lib/rabbit/author-configuration.rb

Constant Summary

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetText

included

Constructor Details

#initialize(logger = nil) ⇒ AuthorConfiguration

Returns a new instance of AuthorConfiguration.



31
32
33
34
# File 'lib/rabbit/author-configuration.rb', line 31

def initialize(logger=nil)
  @logger = logger || Logger.default
  clear
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



29
30
31
# File 'lib/rabbit/author-configuration.rb', line 29

def email
  @email
end

#loggerObject

Returns the value of attribute logger.



28
29
30
# File 'lib/rabbit/author-configuration.rb', line 28

def logger
  @logger
end

#markup_languageObject

Returns the value of attribute markup_language.



29
30
31
# File 'lib/rabbit/author-configuration.rb', line 29

def markup_language
  @markup_language
end

#nameObject

Returns the value of attribute name.



29
30
31
# File 'lib/rabbit/author-configuration.rb', line 29

def name
  @name
end

#rubygems_userObject

Returns the value of attribute rubygems_user.



30
31
32
# File 'lib/rabbit/author-configuration.rb', line 30

def rubygems_user
  @rubygems_user
end

#slideshare_userObject

Returns the value of attribute slideshare_user.



30
31
32
# File 'lib/rabbit/author-configuration.rb', line 30

def slideshare_user
  @slideshare_user
end

#speaker_deck_userObject

Returns the value of attribute speaker_deck_user.



30
31
32
# File 'lib/rabbit/author-configuration.rb', line 30

def speaker_deck_user
  @speaker_deck_user
end

Instance Method Details

#clearObject



56
57
58
59
60
61
62
63
# File 'lib/rabbit/author-configuration.rb', line 56

def clear
  @markup_language   = nil
  @name              = nil
  @email             = nil
  @rubygems_user     = nil
  @slideshare_user   = nil
  @speaker_deck_user = nil
end

#loadObject



36
37
38
39
40
41
42
43
44
# File 'lib/rabbit/author-configuration.rb', line 36

def load
  return unless File.exist?(path)
  conf = YAML.load(File.read(path))
  clear
  merge!(conf)
rescue
  format = _("Failed to read author configuration: %s: %s")
  @logger.error(format % [path, $!.message])
end

#merge!(conf) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/rabbit/author-configuration.rb', line 65

def merge!(conf)
  @markup_language   = conf["markup_language"]   || @markup_language
  @name              = conf["name"]              || @name
  @email             = conf["email"]             || @email
  @rubygems_user     = conf["rubygems_user"]     || @rubygems_user
  @slideshare_user   = conf["slideshare_user"]   || @slideshare_user
  @speaker_deck_user = conf["speaker_deck_user"] || @spearker_deck_user
end

#saveObject



46
47
48
49
50
51
52
53
54
# File 'lib/rabbit/author-configuration.rb', line 46

def save
  create_directory(File.dirname(path))
  create_file(path) do |conf_file|
    conf_file.print(to_yaml)
  end
rescue
  format = _("Failed to write author configuration: %s: %s")
  @logger.error(format % [path, $!.message])
end

#to_hashObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/rabbit/author-configuration.rb', line 74

def to_hash
  {
    "markup_language"   => @markup_language,
    "name"              => @name,
    "email"             => @email,
    "rubygems_user"     => @rubygems_user,
    "slideshare_user"   => @slideshare_user,
    "speaker_deck_user" => @speaker_deck_user,
  }
end

#to_yamlObject



85
86
87
# File 'lib/rabbit/author-configuration.rb', line 85

def to_yaml
  to_hash.to_yaml
end