moodwall 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9054fee489308683737f0cbeb2b2276598c7b3bed2b7067a90b7de4d0700782
4
- data.tar.gz: 62c291f465fd0578bcfbba613228a5486966815b235e8a7af541e61aa5f80b15
3
+ metadata.gz: 76cbd152fdaa9e375db9be0a48154f644e4a17caff9f57a20e34ad38bff19337
4
+ data.tar.gz: 315a703cf9ea243504b8b83f4c511025ea263938ab7039304c763de5cc1da77b
5
5
  SHA512:
6
- metadata.gz: 546cecc934bcb6cd962224a9ca2348c1c83793a004cec91f876352efb805000bf17279bbbdd8ca41fcb941822caf75c34fdb0bb3eed8cebb9860893a81cd7302
7
- data.tar.gz: 5c7a710ca05a40cbd2154321ebfda7916fe21cba972cff503384da5e6fc5f385357d3288b2f76dcf00d97dff4c92a6615c81741e2ceff375faf61fe26b9d6e24
6
+ metadata.gz: 07dc85557daa890c2a182e43300b1602f63009f5563842f4d89f28b97e1a5d00a569756cc342a19da90d57387df04791ad5d6e0e3f1ba8744a3515bd17dcab4f
7
+ data.tar.gz: 1bcb8382ed7cd79e8d4680d8a1cb672b3bad4d41df086cdf431f9585c1a3085748dad2b9424677bd7305c47c909a7255f00c7991927affaa356e1063cb49151c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moodwall (0.1.4)
4
+ moodwall (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -14,6 +14,17 @@ Install it yourself as:
14
14
 
15
15
  $ gem install moodwall
16
16
 
17
+ ## Configuration
18
+
19
+ Create a `config.yml` file at `~/.config/moodwall/config.yml` and specify
20
+ command to change wallpaper in your distro. Here is defaults:
21
+
22
+ ``` yaml
23
+ executable:
24
+ command: feh
25
+ arguments: --bg-fill
26
+ ```
27
+
17
28
  ## Usage examples
18
29
 
19
30
  ``` shell
@@ -19,9 +19,7 @@ when options.add && options.wallpaper && !options.path.nil? && !options.mood_nam
19
19
  mood = Moodwall::Mood.find_by_name(options.mood_name)
20
20
  Moodwall::Wallpaper.new({path: options.path, mood_id: mood.id}).save
21
21
  when options.change && options.wallpaper
22
- executable = Moodwall::Executable.new({ command: "feh", arguments: "--bg-fill" })
23
- wallpaper = Moodwall::Wallpaper.sample
24
- executable.execute(wallpaper.path)
22
+ Moodwall::Executable.execute(Moodwall::Wallpaper.sample.path)
25
23
  when options.list && options.mood
26
24
  puts Moodwall::Mood.list_names
27
25
  when options.list && options.wallpaper
@@ -1,3 +1,5 @@
1
+ require "moodwall/config_file"
2
+ require "moodwall/config"
1
3
  require "moodwall/executable"
2
4
  require "moodwall/version"
3
5
  require "moodwall/repository"
@@ -0,0 +1,26 @@
1
+ module Moodwall
2
+ class Config
3
+ DEFAULTS = {
4
+ executable: {
5
+ command: "feh",
6
+ arguments: "--bg-fill"
7
+ }
8
+ }.freeze
9
+
10
+ attr_reader :executable
11
+
12
+ def initialize(config_file = ConfigFile.new)
13
+ @data = config_file.data
14
+ @executable = decorate_executable(@data.fetch("executable", {}))
15
+ end
16
+
17
+ private
18
+
19
+ def decorate_executable(data)
20
+ Struct.new(:command, :arguments).new(
21
+ data.fetch("command", DEFAULTS[:executable][:command]),
22
+ data.fetch("arguments", DEFAULTS[:executable][:arguments])
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require "yaml"
2
+ require "fileutils"
3
+
4
+ module Moodwall
5
+ class ConfigFile
6
+ DIRECTORY = "#{ Dir.home }/.config/moodwall".freeze
7
+ FILE = "config.yml".freeze
8
+
9
+ attr_reader :data, :path
10
+
11
+ def initialize
12
+ @path = File.join(DIRECTORY, FILE)
13
+ create_directory && prepare_file
14
+ @data = YAML.safe_load(File.read(path)) || {}
15
+ end
16
+
17
+ private
18
+
19
+ def create_directory
20
+ FileUtils.mkdir_p(DIRECTORY)
21
+ end
22
+
23
+ def prepare_file
24
+ FileUtils.touch(path)
25
+ end
26
+ end
27
+ end
@@ -4,12 +4,17 @@ module Moodwall
4
4
  class Executable
5
5
  attr_reader :command, :arguments
6
6
 
7
- def initialize(options = {})
8
- @command = options.fetch(:command, nil)
9
- @arguments = options.fetch(:arguments, nil)
7
+ def initialize(options = {}, config = Config.new)
8
+ @config = config.executable
9
+ @command = options.fetch(:command, @config.command)
10
+ @arguments = options.fetch(:arguments, @config.arguments)
10
11
  error_if_missing
11
12
  end
12
13
 
14
+ def self.execute(path)
15
+ new.execute(path)
16
+ end
17
+
13
18
  def error_if_missing
14
19
  raise(MissingExecutableError, "Can't find the `#{ command }`") unless installed?
15
20
  end
@@ -1,3 +1,3 @@
1
1
  module Moodwall
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moodwall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valiantsin Mikhaliuk
@@ -130,6 +130,8 @@ files:
130
130
  - bin/moodwall
131
131
  - bin/setup
132
132
  - lib/moodwall.rb
133
+ - lib/moodwall/config.rb
134
+ - lib/moodwall/config_file.rb
133
135
  - lib/moodwall/executable.rb
134
136
  - lib/moodwall/mood.rb
135
137
  - lib/moodwall/optparse.rb