boto 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fb2d70a7b7635babe5e2aca11cc79b83932bfe5
4
+ data.tar.gz: 1e44582a45a3095d27a36567c68d46108402e4a7
5
+ SHA512:
6
+ metadata.gz: ecacd6bc64d974dc254720fd6eb423a8cb9b3e2c3e185f7a119cd10eee0d5b97c91d7c8abf12a1e4694b7cb66b521b241d685f6695998b7b06dc789783b9fa10
7
+ data.tar.gz: bad811201d9187aacc8819ff424706812f9935e44552e167fccd8eb677baa87eb7f5970b170e2c8e13eb6906e82a860a75df1459d74f420292aed4eec7e118c3
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boto.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Manuel Albarrán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Boto
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/boto`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'boto'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install boto
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/boto.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'boto'
4
+ puts "boto"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "boto"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boto/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boto"
8
+ spec.version = Boto::VERSION
9
+ spec.executables << 'boto'
10
+ spec.authors = ["Manuel Albarrán"]
11
+ spec.email = ["weap88@gmail.com"]
12
+
13
+ spec.summary = %q{Bot framefork}
14
+ spec.description = %q{Bot framefork}
15
+ spec.homepage = "https://github.com/weapp/boto"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "dotenv", "~> 2.1.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'boto'
4
+ puts "boto"
@@ -0,0 +1,32 @@
1
+ require "boto/version"
2
+
3
+ module Boto
4
+ class << self
5
+ attr_accessor :app_class, :cache, :logger
6
+
7
+ def root
8
+ application && application.config.root
9
+ end
10
+
11
+ def application
12
+ @application ||= (app_class.instance if app_class)
13
+ end
14
+
15
+ def router
16
+ @router ||= Boto::Router.new
17
+ end
18
+
19
+ def groups(*groups)
20
+ env = Boto.env
21
+ groups.unshift(:default, env)
22
+ groups.concat ENV["CIDER_GROUPS"].to_s.split(",")
23
+ groups.compact!
24
+ groups.uniq!
25
+ groups
26
+ end
27
+
28
+ def env
29
+ @_env ||= ENV["CIDER_ENV"] || ENV["APP_ENV"] || "development"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ require "boto"
2
+ require "boto/application"
3
+ require "boto/router"
4
+ require "boto/bot"
@@ -0,0 +1,58 @@
1
+ require "singleton"
2
+ require "ostruct"
3
+ require "dotenv"
4
+
5
+ module Boto
6
+ class Application
7
+ include Singleton
8
+
9
+ class << self
10
+ attr_accessor :called_from
11
+
12
+ def inherited(app_class)
13
+ Boto.app_class = app_class
14
+
15
+ app_class.called_from = begin
16
+ call_stack = if Kernel.respond_to?(:caller_locations)
17
+ caller_locations.map { |l| l.absolute_path || l.path }
18
+ else
19
+ # Remove the line number from backtraces making sure we don't leave anything behind
20
+ caller.map { |p| p.sub(/:\d+.*/, '') }
21
+ end
22
+
23
+ File.dirname(call_stack.detect { |p| p !~ %r[boto[\w.-]*/lib/boto] })
24
+ end
25
+
26
+ $LOAD_PATH.unshift("#{root}/lib")
27
+ Dir["#{root}/lib/**/*.rb"].sort.each { |file| require file }
28
+ Dotenv.load
29
+
30
+ super
31
+ end
32
+
33
+ def find_root(path)
34
+ Pathname.new(path).dirname
35
+ end
36
+
37
+ def config
38
+ @config ||= OpenStruct.new(root: find_root(Boto.app_class.called_from))
39
+ end
40
+
41
+ def root
42
+ config.root
43
+ end
44
+ end
45
+
46
+ def config
47
+ self.class.config
48
+ end
49
+
50
+ def root
51
+ config.root
52
+ end
53
+
54
+ def adapter
55
+ config.adapter
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,11 @@
1
+ module Boto
2
+ class Bot
3
+ attr_accessor :env
4
+
5
+ def initialize(env)
6
+ @env = env
7
+ end
8
+ end
9
+ end
10
+
11
+
@@ -0,0 +1,13 @@
1
+ ARGV << '--help' if ARGV.empty?
2
+
3
+ aliases = {
4
+ "c" => "console",
5
+ "s" => "server",
6
+ }
7
+
8
+ command = ARGV.shift
9
+ command = aliases[command] || command
10
+
11
+ require 'boto/commands/tasks'
12
+
13
+ Boto::Commands::Tasks.new(ARGV).run_command!(command)
@@ -0,0 +1,2 @@
1
+ require "boto/server"
2
+
@@ -0,0 +1,75 @@
1
+ module Boto
2
+ module Commands
3
+ class Tasks
4
+ COMMAND_WHITELIST = %w(console server runner new version)
5
+
6
+ def initialize(argv)
7
+ @args = argv
8
+ end
9
+
10
+ def run_command!(command)
11
+ command = parse_command(command)
12
+
13
+ send(command) if COMMAND_WHITELIST.include?(command)
14
+ end
15
+
16
+ def console
17
+ set_application_directory!
18
+
19
+ require APP_PATH
20
+ Dir.chdir(Boto.application.root)
21
+
22
+ require "pry" rescue nil
23
+ if defined? Pry
24
+ Pry.start
25
+ else
26
+ require "irb"
27
+ IRB.start
28
+ end
29
+ end
30
+
31
+ def server
32
+ set_application_directory!
33
+ require_command!("server")
34
+
35
+ Boto::Server.new.tap do |server|
36
+ # We need to require application after the server sets environment,
37
+ # otherwise the --environment option given to the server won't propagate.
38
+ require APP_PATH
39
+ Dir.chdir(Boto.application.root)
40
+ server.start
41
+ end
42
+ end
43
+
44
+ def runner
45
+ end
46
+
47
+ def new
48
+ end
49
+
50
+ def version
51
+ end
52
+
53
+ private
54
+
55
+ def set_application_directory!
56
+ Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
57
+ end
58
+
59
+ def require_command!(command)
60
+ require "boto/commands/#{command}"
61
+ end
62
+
63
+ def parse_command(command)
64
+ case command
65
+ when '--version', '-v'
66
+ 'version'
67
+ when '--help', '-h'
68
+ 'help'
69
+ else
70
+ command
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,36 @@
1
+ module Boto
2
+ class Router
3
+ def proccess_message(env)
4
+ listeners.each do |_desc, condition, method|
5
+ next unless condition.call(env)
6
+ if method.respond_to?(:call)
7
+ method.call(env)
8
+ elsif method.to_s.include? "#"
9
+ klass, method = method.to_s.split("#", 2)
10
+ instance = Math.const_get(klass).new(env)
11
+ instance.public_send(method)
12
+ end
13
+ end
14
+ end
15
+
16
+ def listeners
17
+ @listeners ||= []
18
+ end
19
+
20
+ def listen(matcher, params = {})
21
+ method = params.fetch(:to, matcher)
22
+ listeners << [matcher, matcher_to_proc(matcher), method]
23
+ end
24
+
25
+ def draw(&block)
26
+ instance_exec(&block)
27
+ end
28
+
29
+ def matcher_to_proc(matcher)
30
+ return -> (_update) { true } if matcher == :default
31
+ return matcher if matcher.respond_to?(:call)
32
+ return -> (update) { matcher =~ update[:text].to_s } if matcher.is_a?(Regexp)
33
+ matcher_to_proc(%r{^/?(#{matcher})([\s@]|$)}i)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module Boto
2
+ class Server
3
+ def adapter
4
+ Boto.application.adapter
5
+ end
6
+
7
+ def start
8
+ require "#{Boto.root}/config/router"
9
+ adapter.updates.select(&:itself).each(&method(:tick!))
10
+ end
11
+
12
+ def tick!(update)
13
+ p update
14
+ Boto.router.proccess_message(update)
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,3 @@
1
+ module Boto
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Albarrán
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Bot framefork
70
+ email:
71
+ - weap88@gmail.com
72
+ executables:
73
+ - boto
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - bin/boto
82
+ - bin/console
83
+ - bin/setup
84
+ - boto.gemspec
85
+ - exe/boto
86
+ - lib/boto.rb
87
+ - lib/boto/all.rb
88
+ - lib/boto/application.rb
89
+ - lib/boto/bot.rb
90
+ - lib/boto/commands.rb
91
+ - lib/boto/commands/server.rb
92
+ - lib/boto/commands/tasks.rb
93
+ - lib/boto/router.rb
94
+ - lib/boto/server.rb
95
+ - lib/boto/version.rb
96
+ homepage: https://github.com/weapp/boto
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Bot framefork
120
+ test_files: []
121
+ has_rdoc: