Skip to content

Commit

Permalink
Merge pull request #38 from leoamigood/la_turnpike
Browse files Browse the repository at this point in the history
Puma/Redis
  • Loading branch information
leoamigood authored Mar 14, 2017
2 parents 8433385 + 23da331 commit f39a8ab
Show file tree
Hide file tree
Showing 37 changed files with 608 additions and 338 deletions.
3 changes: 2 additions & 1 deletion .env.backend
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PORT=3000
RAILS_ENV=development

DB_HOST=postgres
DB_PORT=5432

REDIS_URL=redis://redis:6379/0
2 changes: 1 addition & 1 deletion .env.postgres.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
POSTGRES_USER=sa
POSTGRES_USER=postgres
POSTGRES_PASSWORD=q_7qrNVD5tRMV
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc

# Use Unicorn as the app server
# gem 'unicorn'
gem 'puma'
gem 'puma-heroku'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
Expand All @@ -42,6 +44,7 @@ gem 'kaminari'
gem 'api-pagination'
gem 'attr_extras'
gem 'aspector'
gem 'turnpike'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
25 changes: 18 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.4)
concurrent-ruby (1.0.5)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
Expand All @@ -79,8 +79,8 @@ GEM
activesupport (>= 4.1.0)
i18n (0.8.1)
ice_nine (0.11.2)
jbuilder (2.6.2)
activesupport (>= 3.0.0, < 5.1)
jbuilder (2.6.3)
activesupport (>= 3.0.0, < 5.2)
multi_json (~> 1.2)
jquery-rails (4.2.2)
rails-dom-testing (>= 1, < 3)
Expand Down Expand Up @@ -108,11 +108,15 @@ GEM
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
msgpack (1.1.0)
multi_json (1.12.1)
multipart-post (2.0.0)
nokogiri (1.7.0.1)
mini_portile2 (~> 2.1.0)
pg (0.19.0)
puma (3.8.0)
puma-heroku (1.0.0)
puma (~> 3.0)
rack (1.6.5)
rack-cors (0.4.1)
rack-test (0.6.3)
Expand All @@ -128,7 +132,7 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.5)
sprockets-rails
rails-api (0.4.0)
rails-api (0.4.1)
actionpack (>= 3.2.11)
railties (>= 3.2.11)
rails-deprecated_sanitizer (1.0.3)
Expand All @@ -146,6 +150,7 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rdoc (4.3.0)
redis (3.3.3)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
Expand Down Expand Up @@ -191,14 +196,17 @@ GEM
faraday
virtus
thor (0.19.4)
thread_safe (0.3.5)
thread_safe (0.3.6)
tilt (2.0.6)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
turnpike (0.8.0)
msgpack (~> 1.0)
redis (~> 3.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (3.0.4)
uglifier (3.1.6)
execjs (>= 0.3.0, < 3)
virtus (1.0.5)
axiom-types (~> 0.1)
Expand Down Expand Up @@ -226,6 +234,8 @@ DEPENDENCIES
jquery-rails
kaminari
pg
puma
puma-heroku
rack-cors
rails (= 4.2.5)
rails-api
Expand All @@ -236,8 +246,9 @@ DEPENDENCIES
spring
telegram-bot-ruby
turbolinks
turnpike
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.14.4
1.14.6
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Best
class << self
Expand All @@ -16,7 +16,7 @@ def execute(channel, limit)
target do
def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Telegram::Command::Action::BEST, channel, message)
Telegram::Validator.validate!(Telegram::Action::Command::BEST, channel, message)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Telegram
module Command
module Action
module Action
module Command
BEST = '/best'
CREATE = '/create'
GUESS = '/guess'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Create
class << self
Expand All @@ -10,9 +10,6 @@ def ask(channel)
end

def execute(channel, message, options)
return unless Telegram::CommandQueue.assert(self)

Telegram::CommandQueue.clear
case options[:strategy]
when :by_word
game = GameEngineService.create_by_word(Realm::Telegram.new(channel, message.from.id), options[:word])
Expand All @@ -25,18 +22,36 @@ def execute(channel, message, options)
end
TelegramMessenger.game_created(game)
end

def self?
"proc { |cls| cls == #{self.name} }"
end
end
end

aspector(Create, class_methods: true) do
target do
def assert(*args, &block)
channel, message = *args
Telegram::CommandQueue::Queue.new(channel).assert(self)
end

def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Action::CREATE, channel, message)
Telegram::Validator.validate!(Command::CREATE, channel, message)
end

def pop(*args, &block)
msg, channel, message = *args
Telegram::CommandQueue::Queue.new(channel).pop

msg
end
end

before_filter :execute, :assert
before :ask, :execute, :permit
after :execute, :pop
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Guess
class << self
Expand All @@ -17,7 +17,7 @@ def execute(channel, message, word)
target do
def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Action::GUESS, channel, message)
Telegram::Validator.validate!(Command::GUESS, channel, message)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Hint
class << self
Expand All @@ -25,7 +25,7 @@ def execute(channel, options)
target do
def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Action::HINT, channel, message)
Telegram::Validator.validate!(Command::HINT, channel, message)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Language
class << self
Expand All @@ -10,26 +10,42 @@ def ask(channel)
end

def execute(channel, language)
return unless Telegram::CommandQueue.assert(self)

language = GameEngineService.language(language.upcase)
dictionary = Dictionary.where(lang: language).order('RANDOM()').first

GameEngineService.settings(channel, {dictionary_id: dictionary.id, language: language})
TelegramMessenger.language(language)
end

def self?
"proc { |cls| cls == #{self.name} }"
end
end
end

aspector(Language, class_methods: true) do
target do
def assert(*args, &block)
channel, message = *args
Telegram::CommandQueue::Queue.new(channel).assert(self)
end

def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Action::LANG, channel, message)
Telegram::Validator.validate!(Command::LANG, channel, message)
end

def pop(*args, &block)
msg, channel, message = *args
Telegram::CommandQueue::Queue.new(channel).pop

msg
end
end

before_filter :execute, :assert
before :ask, :execute, :permit
after :execute, :pop
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aspector'

module Telegram
module Command
module Action

class Level
class << self
Expand All @@ -10,23 +10,39 @@ def ask(channel)
end

def execute(channel, level)
return unless Telegram::CommandQueue.assert(self)

GameEngineService.settings(channel, { complexity: level })
TelegramMessenger.level(level)
end

def self?
"proc { |cls| cls == #{self.name} }"
end
end
end

aspector(Level, class_methods: true) do
target do
def assert(*args, &block)
channel, message = *args
Telegram::CommandQueue::Queue.new(channel).assert(self)
end

def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Action::LEVEL, channel, message)
Telegram::Validator.validate!(Command::LEVEL, channel, message)
end

def pop(*args, &block)
msg, channel, message = *args
Telegram::CommandQueue::Queue.new(channel).pop

msg
end
end

before_filter :execute, :assert
before :ask, :execute, :permit
after :execute, :pop
end
end
end
33 changes: 33 additions & 0 deletions app/services/telegram/action/start.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'aspector'

module Telegram
module Action

class Start
class << self
def execute(channel)
TelegramMessenger.welcome(channel)

queue = Telegram::CommandQueue::Queue.new(channel).reset

ask_language = Telegram::CommandQueue::Exec.new('TelegramMessenger.ask_language', channel, Telegram::Action::Language.self?)
ask_level = Telegram::CommandQueue::Exec.new('TelegramMessenger.ask_level', channel, Telegram::Action::Level.self?)
ask_length = Telegram::CommandQueue::Exec.new('TelegramMessenger.ask_length', channel, Telegram::Action::Create.self?)

queue.push(ask_language, ask_level, ask_length)
end
end
end

aspector(Start, class_methods: true) do
target do
def permit(*args, &block)
channel, message = *args
Telegram::Validator.validate!(Command::START, channel, message)
end
end

before :execute, :permit
end
end
end
Loading

0 comments on commit f39a8ab

Please sign in to comment.