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.


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

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

Instance Attribute Details

#emailObject

Returns the value of attribute email.


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

def email
  @email
end

#loggerObject

Returns the value of attribute logger.


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

def logger
  @logger
end

#markup_languageObject

Returns the value of attribute markup_language.


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

def markup_language
  @markup_language
end

#nameObject

Returns the value of attribute name.


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

def name
  @name
end

#rubygems_userObject

Returns the value of attribute rubygems_user.


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

def rubygems_user
  @rubygems_user
end

#slideshare_userObject

Returns the value of attribute slideshare_user.


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

def slideshare_user
  @slideshare_user
end

#speaker_deck_userObject

Returns the value of attribute speaker_deck_user.


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

def speaker_deck_user
  @speaker_deck_user
end

Instance Method Details

#clearObject


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

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

#loadObject


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

def load
  return unless File.exist?(path)
  conf = YAMLLoader.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


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

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


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

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


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

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


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

def to_yaml
  to_hash.to_yaml
end