Class: Lolcommits::Configuration
- Inherits:
-
Object
- Object
- Lolcommits::Configuration
- Defined in:
- lib/lolcommits/configuration.rb
Constant Summary collapse
- LOLBASEDIR =
ENV['LOLCOMMITS_DIR'] || File.join(ENV['HOME'], '.lolcommits')
- LOLCOMMITS_ROOT =
File.join(File.dirname(__FILE__), '../..')
Instance Attribute Summary collapse
Class Method Summary collapse
-
.command_which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
- .git_config_color_always? ⇒ Boolean
- .is_fakecapture? ⇒ Boolean
- .is_linux? ⇒ Boolean
- .is_mac? ⇒ Boolean
- .is_windows? ⇒ Boolean
- .loldir_for(basename) ⇒ Object
- .platform ⇒ Object
- .valid_imagemagick_installed? ⇒ Boolean
Instance Method Summary collapse
- #archivedir ⇒ Object
- #do_configure!(plugin, forced_options = nil) ⇒ Object
- #images ⇒ Object
- #images_today ⇒ Object
-
#initialize(attributes = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #main_image(commit_sha) ⇒ Object
- #most_recent ⇒ Object
- #puts_plugins ⇒ Object
- #raw_image ⇒ Object
- #user_configuration ⇒ Object
- #user_configuration_file ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 11 |
# File 'lib/lolcommits/configuration.rb', line 7 def initialize(attributes={}) attributes.each do |attr, val| self.send("#{attr}=", val) end end |
Instance Attribute Details
#loldir ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/lolcommits/configuration.rb', line 39 def loldir return @loldir if @loldir basename ||= File.basename(Git.open('.').dir.to_s).sub(/^\./, 'dot') basename.sub!(/ /, '-') @loldir = Configuration.loldir_for(basename) end |
Class Method Details
.command_which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH. idea taken from bit.ly/qDaTbY
which('ruby') #=> /usr/bin/ruby
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/lolcommits/configuration.rb', line 164 def self.command_which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = "#{path}/#{cmd}#{ext}" return exe if File.executable? exe } end return nil end |
.git_config_color_always? ⇒ Boolean
156 157 158 |
# File 'lib/lolcommits/configuration.rb', line 156 def self.git_config_color_always? `git config color.ui`.chomp =~ /always/ end |
.is_fakecapture? ⇒ Boolean
144 145 146 |
# File 'lib/lolcommits/configuration.rb', line 144 def self.is_fakecapture? (ENV['LOLCOMMITS_FAKECAPTURE'] == '1' || false) end |
.is_linux? ⇒ Boolean
136 137 138 |
# File 'lib/lolcommits/configuration.rb', line 136 def self.is_linux? RUBY_PLATFORM.to_s.downcase.include?("linux") end |
.is_mac? ⇒ Boolean
132 133 134 |
# File 'lib/lolcommits/configuration.rb', line 132 def self.is_mac? RUBY_PLATFORM.to_s.downcase.include?("darwin") end |
.is_windows? ⇒ Boolean
140 141 142 |
# File 'lib/lolcommits/configuration.rb', line 140 def self.is_windows? !! RUBY_PLATFORM.match(/(win|w)32/) end |
.loldir_for(basename) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/lolcommits/configuration.rb', line 56 def self.loldir_for(basename) loldir = File.join(LOLBASEDIR, basename) if not File.directory? loldir FileUtils.mkdir_p loldir end loldir end |
.platform ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lolcommits/configuration.rb', line 13 def self.platform if is_fakecapture? 'Fake' elsif is_mac? 'Mac' elsif is_linux? 'Linux' elsif is_windows? 'Windows' else raise "Unknown / Unsupported Platform." end end |
.valid_imagemagick_installed? ⇒ Boolean
148 149 150 151 152 153 154 |
# File 'lib/lolcommits/configuration.rb', line 148 def self.valid_imagemagick_installed? return false unless self.command_which('identify') return false unless self.command_which('mogrify') # you'd expect the below to work on its own, but it only handles old versions # and will throw an exception if IM is not installed in PATH MiniMagick::valid_version_installed? end |
Instance Method Details
#archivedir ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/lolcommits/configuration.rb', line 48 def archivedir dir = File.join(loldir, 'archive') if not File.directory? dir FileUtils.mkdir_p dir end dir end |
#do_configure!(plugin, forced_options = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/lolcommits/configuration.rb', line 90 def do_configure!(plugin, =nil) if plugin.nil? || plugin.strip == '' puts_plugins print "Name of plugin to configure: " plugin = STDIN.gets.strip end plugins = Lolcommits::PLUGINS.inject(Hash.new) do |acc, val| p = val.new(nil) acc.merge(p.name => p) end plugin_object = plugins[plugin] if plugin_object.nil? puts "Unable to find plugin: #{plugin}" return end if .nil? = plugin_object..inject(Hash.new) do |acc, option| print "#{option}: " val = STDIN.gets.strip val = true if val == 'true' val = false if val == 'false' acc.merge(option => val) end else = end config = self.user_configuration || Hash.new config[plugin] = File.open(self.user_configuration_file, 'w') do |f| f.write(config.to_yaml) end puts "#{config.to_yaml}\n" puts "Successfully Configured" end |
#images ⇒ Object
69 70 71 |
# File 'lib/lolcommits/configuration.rb', line 69 def images Dir.glob(File.join self.loldir, "*.jpg").sort_by {|f| File.mtime(f)} end |
#images_today ⇒ Object
73 74 75 |
# File 'lib/lolcommits/configuration.rb', line 73 def images_today images.select { |f| Date.parse(File.mtime(f).to_s) === Date.today } end |
#main_image(commit_sha) ⇒ Object
81 82 83 |
# File 'lib/lolcommits/configuration.rb', line 81 def main_image(commit_sha) File.join self.loldir, "#{commit_sha}.jpg" end |
#most_recent ⇒ Object
65 66 67 |
# File 'lib/lolcommits/configuration.rb', line 65 def most_recent Dir.glob(File.join self.loldir, "*.jpg").max_by {|f| File.mtime(f)} end |
#puts_plugins ⇒ Object
85 86 87 88 |
# File 'lib/lolcommits/configuration.rb', line 85 def puts_plugins names = Lolcommits::PLUGINS.collect {|p| p.new(nil).name } puts "Available plugins: #{names.join(', ')}" end |
#raw_image ⇒ Object
77 78 79 |
# File 'lib/lolcommits/configuration.rb', line 77 def raw_image File.join self.loldir, "tmp_snapshot.jpg" end |
#user_configuration ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/lolcommits/configuration.rb', line 27 def user_configuration if File.exists?(user_configuration_file) YAML.load(File.open(user_configuration_file)) else nil end end |
#user_configuration_file ⇒ Object
35 36 37 |
# File 'lib/lolcommits/configuration.rb', line 35 def user_configuration_file "#{self.loldir}/config.yml" end |