chatwork_to 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 5386dcf961a4c15530028ed62b9f4e41fd8e3d85
4
- data.tar.gz: 79386445e66a68997bad48a61f3b05ee8e1d594e
3
+ metadata.gz: 5f1bd5c5dfb0ea1f856b6db64db4411d78beb11f
4
+ data.tar.gz: d7c3328d8f2f6851a86ff5c10b2efbc71541afaa
5
5
  SHA512:
6
- metadata.gz: db861b94786377ac1f475a2dd7d84ceb6ea79237982703880b017f0012c4062855010e4600a34e9f079d60d5187b8a945900fc85301a964eca6406efa3e9b3b0
7
- data.tar.gz: a34af00cb55683484db7e5b601fba1b01d62f55781d817d039e992fc4b3f60f8d740d281b0559be9f5c72980a4210cb0e60070e18d84bcd39a08844796bce391
6
+ metadata.gz: 99cb736a4e0a254b00cdd40e7fd0cd9091c33e676e88d782ca547d4940ba462185e6a2c47b8dcb9a22973770a4250a8a5b9c55ec20121ba330bbf7c095d57f70
7
+ data.tar.gz: 9dc8af7d5d18cbe555920c2b8189541584860024d559072cd58f50441c0c038fcaeaea609950485cba325aae2292a68d3af5aa358879598ca315c640427030ae
data/.gitignore CHANGED
@@ -26,3 +26,7 @@ vendor/bundle/*
26
26
 
27
27
  # configuration file
28
28
  chatwork_to.yml
29
+
30
+ # daemons
31
+ chatwork_to*pid
32
+ chatwork_to*log
data/README.md CHANGED
@@ -36,13 +36,13 @@ notifiers:
36
36
  -
37
37
  name: simple
38
38
  ```
39
- If used `io` option, logger output to file. `rotate`(Default:`weekly`) option is compliant with the rotate option of Ruby Logger.
39
+ If used `io` option, logger output to file. `rotation`(Default:`weekly`) option is compliant with the rotation option of Ruby Logger.
40
40
  ```
41
41
  notifiers:
42
42
  -
43
43
  name: simple
44
44
  io: '~/logs/chatwork_to.log'
45
- rotate: weekly
45
+ rotation: weekly
46
46
  ```
47
47
 
48
48
  ### Slack
@@ -56,10 +56,26 @@ notifiers:
56
56
  ```
57
57
 
58
58
  ## Run
59
+ ### Foreground
59
60
  ```
60
61
  $ chatwork_to
61
62
  ```
62
63
 
64
+ ### Daemon
65
+ Using [daemons](https://rubygems.org/gems/daemons 'daemos').
66
+ ```
67
+ $ chatwork_to start
68
+ ```
69
+ ```
70
+ $ chatwork_to stop
71
+ ```
72
+ ```
73
+ $ chatwork_to restart
74
+ ```
75
+ ```
76
+ $ chatwork_to status
77
+ ```
78
+
63
79
  ## Contributing
64
80
 
65
81
  1. Fork it ( https://github.com/[my-github-username]/chatwork_to/fork )
data/Rakefile CHANGED
@@ -1,7 +1 @@
1
1
  require "bundler/gem_tasks"
2
- #require "rspec/core/rake_task"
3
- #
4
- #RSpec::Core::RakeTask.new(:spec)
5
- #
6
- #task :default => :spec
7
-
data/bin/chatwork_to CHANGED
@@ -1,4 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'daemons'
2
3
  require 'chatwork_to'
3
4
 
4
- ChatworkTo::Process.new.run
5
+ if ARGV.length > 0
6
+ daemons_opts = {
7
+ ontop: false,
8
+ monitor: true,
9
+ backtrace: true,
10
+ }
11
+ chatwork_to_opts = {
12
+ 'dir' => Dir.pwd
13
+ }
14
+ Daemons.run_proc('chatwork_to', daemons_opts) do
15
+ ChatworkTo::Process.new(chatwork_to_opts).run
16
+ end
17
+ else
18
+ ChatworkTo::Process.new.run
19
+ end
data/chatwork_to.gemspec CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "activesupport", '~> 4.1.4'
22
22
  spec.add_dependency "mechanize", '~> 2.7.3'
23
+ spec.add_dependency "daemons", '~> 1.1.9'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.6"
25
26
  spec.add_development_dependency "rake"
26
- #spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "pry"
28
28
  spec.add_development_dependency "pry-doc"
29
29
  spec.add_development_dependency "pry-stack_explorer"
@@ -7,7 +7,7 @@ notifiers:
7
7
  -
8
8
  name: simple
9
9
  # io: '/path/to/log_file'
10
- # rotate: 'Ruby Logger rotate option'
10
+ # rotation: 'Ruby Logger rotation option'
11
11
  #-
12
12
  # name: slack
13
13
  # token: 'token_here' # API authentication token
@@ -12,26 +12,39 @@ module ChatworkTo
12
12
 
13
13
  private
14
14
  def require_options!(opts)
15
- raise InvalideConfiguration, 'Require configureation: chatwork' if opts['chatwork'].blank?
16
- raise InvalideConfiguration, 'Require configureation: chatwork.email' if opts['chatwork']['email'].blank?
17
- raise InvalideConfiguration, 'Require configureation: chatwork.pass' if opts['chatwork']['pass'].blank?
18
- raise InvalideConfiguration, 'Require configureation: chatwork.rooms' if opts['chatwork']['rooms'].blank?
19
- raise InvalideConfiguration, 'Require configureation: notifiers' if opts['notifiers'].blank?
15
+ raise InvalidConfiguration, 'Require configuration: chatwork' if opts['chatwork'].blank?
16
+ raise InvalidConfiguration, 'Require configuration: chatwork.email' if opts['chatwork']['email'].blank?
17
+ raise InvalidConfiguration, 'Require configuration: chatwork.pass' if opts['chatwork']['pass'].blank?
18
+ raise InvalidConfiguration, 'Require configuration: chatwork.rooms' if opts['chatwork']['rooms'].blank?
19
+ raise InvalidConfiguration, 'Require configuration: notifiers' if opts['notifiers'].blank?
20
20
  end
21
21
 
22
22
  class << self
23
- def load(yaml = nil)
24
- conf_hash = load_yaml(yaml)
25
- new(conf_hash) if conf_hash.present?
23
+ def load(opts = {})
24
+ conf_hash = load_yaml(opts)
25
+ if conf_hash.present?
26
+ new(conf_hash)
27
+ else
28
+ raise InvalidConfiguration, 'Nothing configuration'
29
+ end
26
30
  end
27
31
 
28
32
  private
29
- def default_confs
30
- %w( ./ ~/ ).map{ |dir| dir.concat('chatwork_to.yml') }
33
+ def default_conf_dirs
34
+ %w( ./ ~/ )
31
35
  end
32
36
 
33
- def load_yaml(yaml = nil)
34
- default_confs.unshift(yaml).compact.each do |yml|
37
+ def load_yaml(opts = {})
38
+ confs = default_conf_dirs
39
+ confs.unshift(opts['dir']) if opts['dir'].present?
40
+ confs.unshift(opts['yaml']) if opts['yaml'].present?
41
+
42
+ confs.compact.each do |file_or_dir|
43
+ if File.directory?(file_or_dir)
44
+ yml = File.join(file_or_dir, 'chatwork_to.yml')
45
+ else
46
+ yml = file_or_dir
47
+ end
35
48
  config = YAML.load_file(File.expand_path(yml)) rescue nil
36
49
  return config unless config.nil?
37
50
  end
@@ -40,5 +53,5 @@ module ChatworkTo
40
53
  end
41
54
  end
42
55
 
43
- class InvalideConfiguration < StandardError; end;
56
+ class InvalidConfiguration < StandardError; end;
44
57
  end
@@ -6,7 +6,7 @@ module ChatworkTo
6
6
  if opts['io'].is_a?(String)
7
7
  opts['io'] = File.expand_path(opts['io'])
8
8
  FileUtils.mkdir_p(File.dirname(opts['io']))
9
- File.open(opts['io'], 'a')
9
+ FileUtils.touch(opts['io']) unless File.exists?(opts['io'])
10
10
  end
11
11
  @logger = Logger.new(opts['io'], opts['rotation'])
12
12
  @logger.level = Logger::DEBUG
@@ -1,8 +1,8 @@
1
1
  module ChatworkTo
2
2
  class Process
3
3
  CONTINUOUS_ERROR_LIMIT = 10
4
- def initialize(yaml = nil)
5
- @yaml = yaml
4
+ def initialize(opts = {})
5
+ @options = opts
6
6
  prepare
7
7
  end
8
8
 
@@ -43,7 +43,7 @@ module ChatworkTo
43
43
 
44
44
  private
45
45
  def init_config
46
- @config = Config.load(@yaml)
46
+ @config = Config.load(@options)
47
47
  end
48
48
 
49
49
  def init_client
@@ -1,3 +1,3 @@
1
1
  module ChatworkTo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatwork_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nalabjp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-15 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.7.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: daemons
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.9
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement