alphred 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +12 -0
- data/README.md +29 -1
- data/lib/alphred.rb +1 -0
- data/lib/alphred/config.rb +52 -0
- data/lib/alphred/items.rb +1 -0
- data/lib/alphred/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 795eb675cd111730b33cab166f6e9787971eee70
|
4
|
+
data.tar.gz: 688aa2fc538532b9e545fe51618a42e3af931da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8f23d077d9e757647dcd9f159b3affaf4b44fe874d80244293f8aa62a440f56a0e399fc5a51531e02150700033058c13ef1005aaccf64e535f9a2c4fa8e2391
|
7
|
+
data.tar.gz: 143b5a4a6ebf396baeeac8f4eed372236efbd2896b0e457740dbb32c8b278e5f0438ed0edac14d1d422a638f735e3aedf3447d52c2c57a66985ae6cf1d9cfd76
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -86,6 +86,34 @@ This produces the following XML:
|
|
86
86
|
</items>
|
87
87
|
```
|
88
88
|
|
89
|
+
### Workflow Configuration
|
90
|
+
|
91
|
+
`Alphred::Config` provides some helpers for managing configuration that should
|
92
|
+
persist when updating the workflow. This configuration is stored in an JSON
|
93
|
+
file in the workflow data directory.
|
94
|
+
|
95
|
+
``` ruby
|
96
|
+
# config.rb
|
97
|
+
|
98
|
+
module Workflow
|
99
|
+
defaults = { foo: "bar" }
|
100
|
+
Config = Alphred::Config.new(**defaults)
|
101
|
+
```
|
102
|
+
|
103
|
+
The corresponding Script Filter input and Run Action output then look like this:
|
104
|
+
|
105
|
+
``` shell
|
106
|
+
# script filter
|
107
|
+
|
108
|
+
ruby -r./config -e'puts Workflow::Config.filter_xml("{query}")'
|
109
|
+
```
|
110
|
+
|
111
|
+
``` shell
|
112
|
+
# run action
|
113
|
+
|
114
|
+
ruby -r./config -e'Forecast::Config.update!("{query}")'
|
115
|
+
```
|
116
|
+
|
89
117
|
### Releasing
|
90
118
|
|
91
119
|
Including `alphred/tasks` in your `Rakefile` will allow access to Alphred's
|
@@ -95,7 +123,7 @@ dependencies.
|
|
95
123
|
|
96
124
|
## TODO
|
97
125
|
|
98
|
-
-
|
126
|
+
- Add development mode for easier debugging. (Nicer errors, etc.)
|
99
127
|
|
100
128
|
## Development
|
101
129
|
|
data/lib/alphred.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Alphred
|
4
|
+
class Config
|
5
|
+
PATH = File.join(ENV["alfred_workflow_data"], 'config.json')
|
6
|
+
|
7
|
+
def self.load(**defaults)
|
8
|
+
config = self.new(**defaults)
|
9
|
+
config.load!
|
10
|
+
config
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :data
|
14
|
+
|
15
|
+
def initialize(**defaults)
|
16
|
+
@data = Hash[defaults.map {|k,v| [k.to_s, v.to_s] }]
|
17
|
+
end
|
18
|
+
|
19
|
+
def load!
|
20
|
+
self.data.merge!(JSON.load(File.open(PATH)))
|
21
|
+
end
|
22
|
+
|
23
|
+
def update!(json)
|
24
|
+
data = self.data.merge(JSON.load(json))
|
25
|
+
File.write(PATH, JSON.dump(data), mode: ?w)
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
self.data[key.to_s]
|
30
|
+
end
|
31
|
+
|
32
|
+
def filter_xml(filter=nil)
|
33
|
+
filter ||= ""
|
34
|
+
|
35
|
+
items = self.data.map do |key, value|
|
36
|
+
title = if filter.empty?
|
37
|
+
"Unset #{key}"
|
38
|
+
else
|
39
|
+
"Set #{key} to #{filter}"
|
40
|
+
end
|
41
|
+
Item.new(
|
42
|
+
uid: key,
|
43
|
+
arg: JSON.dump(key => filter),
|
44
|
+
title: title,
|
45
|
+
subtitle: self[key]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
Items.new(*items).to_xml
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/alphred/items.rb
CHANGED
data/lib/alphred/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alphred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alpha Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".travis.yml"
|
78
|
+
- CHANGELOG.md
|
78
79
|
- CODE_OF_CONDUCT.md
|
79
80
|
- Gemfile
|
80
81
|
- Guardfile
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- Rakefile
|
84
85
|
- alphred.gemspec
|
85
86
|
- lib/alphred.rb
|
87
|
+
- lib/alphred/config.rb
|
86
88
|
- lib/alphred/icon.rb
|
87
89
|
- lib/alphred/item.rb
|
88
90
|
- lib/alphred/items.rb
|