search-kit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e885ffbac473291386f4b7629cbef29e0f720c8
4
- data.tar.gz: eb250e6aa6300ca73ff6d55e11812a1fdfda3485
3
+ metadata.gz: 3ee72c3e484109f7d168a4c38def107a4aba6405
4
+ data.tar.gz: 6c5a06d38106c3db998d2998a808ba509d8aed10
5
5
  SHA512:
6
- metadata.gz: eb3fe55a47646cdfbde1fef77ee991e31479c6452c129d5f89d96d32491def796b0ee160e086cc0b9ed4ca3196ab8a72d87de2729f32b2b9ea284c29c16b1cbb
7
- data.tar.gz: abf621d8a58167a6e38657f8b0f78406f4dd85985551fbe88e63fffabc8e035c28ca5c659f904dff9b65fbff865f477fdd8291e8e2107412463741ecf2ac11f2
6
+ metadata.gz: 76ea4042783f93b854d90a053c781f9eb2c80d70d015395be62246b356b560c0ea71dd7b8e2d43741b7602f7c56310950758125cb57f3e4b06bd3cea9d6224e4
7
+ data.tar.gz: 99f49469151c8977dc9a440cab9ac0ec4ca36d3e9eb9bfcc882761ff59a312ffbb6c9e534231ad323a7415bd943d897348661540ea52e05b50f2eb5816fbb705
@@ -21,19 +21,12 @@ module SearchKit
21
21
  extend Configuration
22
22
 
23
23
  configure do |config|
24
- config.app_uri = ENV.fetch("APP_URI", "http://localhost:8080")
25
- config.app_env = ENV.fetch("APP_ENV", "development")
26
- config.app_dir = ENV.fetch("APP_DIR", nil) || Dir.pwd
27
- config.verbose = ENV.fetch("APP_VERBOSE", true)
28
-
29
- config.log_dir = ENV.fetch("LOG_DIR") do
30
- Dir.mkdir('log') unless Dir.exist?('log')
31
-
32
- 'log'
33
- end
34
-
35
- config.config_dir = File.join(config.app_dir, "config")
36
- config.token_strategy = -> token { nil }
24
+ config.app_dir = fetch("APP_DIR")
25
+ config.app_env = fetch("APP_ENV")
26
+ config.app_uri = fetch("APP_URI")
27
+ config.config_dir = File.join(config.app_dir, "config")
28
+ config.log_dir = fetch("LOG_DIR")
29
+ config.verbose = fetch("APP_VERBOSE")
37
30
  end
38
31
 
39
32
  I18n.load_path += Dir.glob(File.join(config.config_dir, "locales/*.yml"))
@@ -2,6 +2,8 @@ require 'thor'
2
2
 
3
3
  module SearchKit
4
4
  class CLI < Thor
5
+ include Messaging
6
+
5
7
  desc "documents", "Manage individual SearchKit documents"
6
8
  subcommand "documents", SearchKit::Documents::CLI
7
9
 
@@ -14,8 +16,18 @@ module SearchKit
14
16
  desc "search", "Quickly search your indices"
15
17
  subcommand "search", SearchKit::Search::CLI
16
18
 
17
- desc "config", "Configure your SearchKit settings"
18
- def config
19
+ desc "config SETTING [VALUE]", "Configure or view your SearchKit settings"
20
+ def config(setting, value = nil)
21
+ if value
22
+ SearchKit.set_config(setting, value)
23
+ info "Set #{setting}: #{value}"
24
+ else
25
+ value = SearchKit.show_config(setting)
26
+ info "SearchKit settings for #{setting}:"
27
+ info " - ~/.search-kit/config.yml: #{value}"
28
+ info " - ENV: #{ENV.fetch(setting.upcase, "Not set")}"
29
+ info " - Runtime: #{SearchKit.config.send(setting)}"
30
+ end
19
31
  end
20
32
  end
21
33
  end
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'yaml'
3
3
  require 'uri'
4
+ require 'user_config'
4
5
 
5
6
  module SearchKit
6
7
  module Configuration
@@ -10,7 +11,48 @@ module SearchKit
10
11
  end
11
12
 
12
13
  def config
13
- @config ||= OpenStruct.new
14
+ return @config if @config
15
+ root = UserConfig.new(".search-kit")
16
+ yaml = root['config.yml']
17
+ config = OpenStruct.new
18
+
19
+ yaml.each { |key, value| config.send("#{key}=", value) }
20
+ @config = config
21
+ end
22
+
23
+ def set_config(key, value)
24
+ root = UserConfig.new(".search-kit")
25
+ yaml = root['config.yml']
26
+
27
+ yaml[key] = value
28
+ yaml.save
29
+ end
30
+
31
+ def show_config(key)
32
+ root = UserConfig.new(".search-kit")
33
+ root['config.yml'][key]
34
+ end
35
+
36
+ def fetch(key)
37
+ ENV.fetch(key, show_config(key.downcase) || default(key.to_sym))
38
+ end
39
+
40
+ private
41
+
42
+ def default(key)
43
+ default_table = {
44
+ APP_URI: "http://localhost:8080",
45
+ APP_ENV: "development",
46
+ APP_DIR: File.expand_path("../../", __dir__),
47
+ APP_VERBOSE: true,
48
+ LOG_DIR: default_log_dir
49
+ }.fetch(key, nil)
50
+ end
51
+
52
+ def default_log_dir
53
+ Dir.mkdir('log') unless Dir.exist?('log')
54
+
55
+ 'log'
14
56
  end
15
57
 
16
58
  end
@@ -9,7 +9,8 @@ module SearchKit
9
9
  attr_reader :connection
10
10
 
11
11
  def initialize
12
- @connection = SearchKit::Client.connection
12
+ uri = [SearchKit.config.app_uri, "documents"].join("/")
13
+ @connection = Faraday.new(uri)
13
14
  end
14
15
 
15
16
  def create(slug, options)
@@ -6,15 +6,17 @@ module SearchKit
6
6
  class Events
7
7
  autoload :CLI, 'search_kit/events/cli'
8
8
  autoload :Publish, 'search_kit/events/publish'
9
+ autoload :Poll, 'search_kit/events/poll'
9
10
 
10
11
  attr_reader :connection
11
12
 
12
13
  def initialize
13
- @connection = SearchKit::Client.connection
14
+ uri = [SearchKit.config.app_uri, "events"].join("/")
15
+ @connection = Faraday.new(uri)
14
16
  end
15
17
 
16
18
  def complete(id)
17
- response = connection.delete("/api/events/#{id}")
19
+ response = connection.delete(id)
18
20
  body = JSON.parse(response.body, symbolize_names: true)
19
21
 
20
22
  fail Errors::EventNotFound if response.status == 404
@@ -23,13 +25,13 @@ module SearchKit
23
25
  end
24
26
 
25
27
  def index
26
- response = connection.get('/api/events')
28
+ response = connection.get
27
29
 
28
30
  JSON.parse(response.body, symbolize_names: true)
29
31
  end
30
32
 
31
33
  def show(id)
32
- response = connection.get("/api/events/#{id}")
34
+ response = connection.get(id)
33
35
  body = JSON.parse(response.body, symbolize_names: true)
34
36
 
35
37
  fail Errors::EventNotFound if response.status == 404
@@ -38,7 +40,7 @@ module SearchKit
38
40
  end
39
41
 
40
42
  def pending(channel)
41
- response = connection.get("/api/events?filter[channel]=#{channel}")
43
+ response = connection.get('', "filter[channel]" => channel)
42
44
 
43
45
  JSON.parse(response.body, symbolize_names: true)
44
46
  end
@@ -0,0 +1,32 @@
1
+ module SearchKit
2
+ class Events
3
+ # This file houses the polling loop of the Event service.
4
+ #
5
+ class Poll
6
+ autoload :Process, 'search_kit/events/poll/process'
7
+
8
+ def self.perform(channel, &block)
9
+ new(channel, &block).perform
10
+ end
11
+
12
+ attr_reader :block, :channel
13
+
14
+ def initialize(channel, &block)
15
+ @block = block
16
+ @channel = channel
17
+ end
18
+
19
+ def perform
20
+ loop do
21
+ process_queue
22
+ sleep 1
23
+ end
24
+ end
25
+
26
+ def process_queue
27
+ SearchKit::Events::Poll::Process.perform(channel, &block)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ module SearchKit
2
+ class Events
3
+ class Poll
4
+ # The logic of interacting with the event service to retrieve and process
5
+ # events is contained here.
6
+ #
7
+ class Process
8
+ def self.perform(channel, &block)
9
+ new(channel, &block).perform
10
+ end
11
+
12
+ attr_reader :block, :channel, :client
13
+
14
+ def initialize(channel, &block)
15
+ @block = block
16
+ @channel = channel
17
+ @client = SearchKit::Events.new
18
+ end
19
+
20
+ def perform
21
+ events.each do |event|
22
+ begin
23
+ block.call(event)
24
+ rescue
25
+ raise
26
+ else
27
+ client.complete(event.id)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def events
35
+ response = client.pending(channel)
36
+ response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -9,7 +9,8 @@ module SearchKit
9
9
  attr_reader :connection
10
10
 
11
11
  def initialize
12
- @connection = SearchKit::Client.connection
12
+ uri = [SearchKit.config.app_uri, "indices"].join("/")
13
+ @connection = Faraday.new(uri)
13
14
  end
14
15
 
15
16
  def show(slug)
@@ -9,7 +9,8 @@ module SearchKit
9
9
  attr_reader :connection
10
10
 
11
11
  def initialize
12
- @connection ||= SearchKit::Client.connection
12
+ uri = [SearchKit.config.app_uri, "search"].join("/")
13
+ @connection = Faraday.new(uri)
13
14
  end
14
15
 
15
16
  def search(slug, options)
@@ -12,7 +12,7 @@ module SearchKit
12
12
  module VERSION
13
13
  MAJOR = 0
14
14
  MINOR = 0
15
- TINY = 1
15
+ TINY = 2
16
16
  PRE = nil
17
17
 
18
18
  STRING = [ MAJOR, MINOR, TINY, PRE ].compact.join(".")
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "ansi", "~> 1.5"
29
29
  spec.add_dependency "faraday", "~> 0.9"
30
30
  spec.add_dependency "thor", "~> 0.19"
31
+ spec.add_dependency "user_config", "~> 0.0"
31
32
  spec.add_dependency "i18n", "~> 0.7"
32
33
 
33
34
  spec.add_development_dependency "bundler", "~> 1.8"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ansi
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: user_config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: i18n
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -186,7 +200,6 @@ files:
186
200
  - config/locales/en.yml
187
201
  - lib/search_kit.rb
188
202
  - lib/search_kit/cli.rb
189
- - lib/search_kit/client.rb
190
203
  - lib/search_kit/configuration.rb
191
204
  - lib/search_kit/documents.rb
192
205
  - lib/search_kit/documents/cli.rb
@@ -198,6 +211,8 @@ files:
198
211
  - lib/search_kit/events/cli/pending.rb
199
212
  - lib/search_kit/events/cli/publish.rb
200
213
  - lib/search_kit/events/cli/status.rb
214
+ - lib/search_kit/events/poll.rb
215
+ - lib/search_kit/events/poll/process.rb
201
216
  - lib/search_kit/events/publish.rb
202
217
  - lib/search_kit/indices.rb
203
218
  - lib/search_kit/indices/cli.rb
@@ -1,9 +0,0 @@
1
- require 'faraday'
2
-
3
- module SearchKit
4
- module Client
5
- def self.connection
6
- @connection ||= Faraday.new(SearchKit.config.app_uri)
7
- end
8
- end
9
- end