ellen 0.0.2 → 0.0.3

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: 1a7c6482b9bfde724af1ad6fc7ce974df7af1714
4
- data.tar.gz: 77363d87ff9d8c0894f0b832c3ccb9221a6abee9
3
+ metadata.gz: 29ad3aa6bd8349d58077ff020f9bea37e7fca57b
4
+ data.tar.gz: b37cbe10c8c7878b2b3a7b036b64b4307128c1c6
5
5
  SHA512:
6
- metadata.gz: 28c4776e263d80a48539d6bb0863b312ac9c78aaf14acc03378ee08ac97cd62e74436b9382ee29bc89570b640364942a5f70e73d8feb4e72d1976561e05e4619
7
- data.tar.gz: 7766b5ec90898a46545db4a4a6a92cf650971f7fd79707848e407e98fcf49e7d20e7fd4202680539cd5157ddf04eb26447ad0d293bdfe42ac24e60950f4adb0a
6
+ metadata.gz: 6ec91fd6d9acf7d972d68d4493f5cfb058671361a47e6eee34b7f909d2c489c546b4691b195a619f15f851cb2e03444eb9c4152bfebb7532123c5ab0299892dc
7
+ data.tar.gz: ee94c91e91fc28f5188810ad31b35947c239f32445119dd7c91173976e05bbb005fcfbabfa3f95a3d674dd1b37bd4c4111ad6e981a9d94ddbfecf6ffd5028191
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
- ### 0.0.2
1
+ ## 0.0.3
2
+ * Add env DSL to define adapter
3
+
4
+ ## 0.0.2
2
5
  * Add Handler DSL Syntax
3
6
  * Add --load option to load a ruby file before running
4
7
 
5
- ### 0.0.1
8
+ ## 0.0.1
6
9
  * 1st release
data/README.md CHANGED
@@ -12,3 +12,6 @@ $ cd ellen # Changes to ./ellen/
12
12
  $ vi Gemfile # Adds your favorite plugin gems
13
13
  $ bundle exec ellen --adapter=shell # Run your chatterbot with specified adapter
14
14
  ```
15
+
16
+ ## Adapters
17
+ * [ellen-hipchat](https://github.com/r7kamura/ellen-hipchat)
@@ -16,6 +16,18 @@ module Ellen
16
16
  def inherited(child)
17
17
  Ellen.adapters[child.name.split("::").last.underscore] = child
18
18
  end
19
+
20
+ def env(key, description, options = {})
21
+ envs << Env.new(key, description, options)
22
+ end
23
+
24
+ def envs
25
+ @envs ||= []
26
+ end
27
+
28
+ def usage
29
+ envs.map(&:to_usage).join("\n")
30
+ end
19
31
  end
20
32
 
21
33
  attr_reader :robot, :options
@@ -28,6 +40,12 @@ module Ellen
28
40
  def say(body, options = {})
29
41
  Ellen.logger.info("Not implemented #{self.class}##{__method__} was called")
30
42
  end
43
+
44
+ def validate
45
+ self.class.envs.each(&:validate)
46
+ rescue Env::MissingRequiredKeyError => exception
47
+ Ellen.die("#{exception}\n#{self.class.usage}")
48
+ end
31
49
  end
32
50
  end
33
51
  end
data/lib/ellen/env.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Ellen
2
+ class Env
3
+ attr_reader :key, :description, :options
4
+
5
+ def initialize(key, description, options = {})
6
+ @key = key.to_s
7
+ @description = description
8
+ @options = options
9
+ end
10
+
11
+ def validate
12
+ error if required? && missing?
13
+ end
14
+
15
+ def to_usage
16
+ " %-20s - %s" % [key, description]
17
+ end
18
+
19
+ private
20
+
21
+ def required?
22
+ !options[:optional]
23
+ end
24
+
25
+ def missing?
26
+ !ENV[key]
27
+ end
28
+
29
+ def error
30
+ raise MissingRequiredKeyError, %<ENV["#{key}"] is required but missing>
31
+ end
32
+
33
+ class MissingRequiredKeyError < StandardError
34
+ end
35
+ end
36
+ end
data/lib/ellen/robot.rb CHANGED
@@ -13,6 +13,7 @@ module Ellen
13
13
  def run
14
14
  bundle
15
15
  setup
16
+ validate
16
17
  adapt
17
18
  end
18
19
 
@@ -46,5 +47,9 @@ module Ellen
46
47
  Ellen.handlers.map {|handler_class| handler_class.new(self) }
47
48
  end
48
49
  memoize :handlers
50
+
51
+ def validate
52
+ adapter.validate
53
+ end
49
54
  end
50
55
  end
data/lib/ellen/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ellen
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/ellen.rb CHANGED
@@ -37,6 +37,7 @@ require "ellen/command_builder"
37
37
  require "ellen/commands/base"
38
38
  require "ellen/commands/generate"
39
39
  require "ellen/commands/run"
40
+ require "ellen/env"
40
41
  require "ellen/handlers/base"
41
42
  require "ellen/handlers/help"
42
43
  require "ellen/logger"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen
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
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-12 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -133,6 +133,7 @@ files:
133
133
  - lib/ellen/commands/base.rb
134
134
  - lib/ellen/commands/generate.rb
135
135
  - lib/ellen/commands/run.rb
136
+ - lib/ellen/env.rb
136
137
  - lib/ellen/handlers/base.rb
137
138
  - lib/ellen/handlers/help.rb
138
139
  - lib/ellen/logger.rb