pleiades 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +2 -2
- data/README.md +23 -0
- data/Rakefile +6 -0
- data/lib/pleiades/core.rb +1 -0
- data/lib/pleiades/core/client.rb +52 -0
- data/lib/pleiades/core/client/wrapper.rb +55 -0
- data/lib/pleiades/core/command.rb +11 -7
- data/lib/pleiades/core/command/base_command.rb +1 -16
- data/lib/pleiades/core/command/executor.rb +16 -0
- data/lib/pleiades/core/command/factory.rb +50 -0
- data/lib/pleiades/core/command/router.rb +28 -27
- data/lib/pleiades/core/command/routing/event_judge_methods.rb +51 -0
- data/lib/pleiades/core/command/routing/event_proccessor.rb +122 -0
- data/lib/pleiades/core/command/routing/nest_blocks.rb +238 -0
- data/lib/pleiades/core/command/routing/path_builder.rb +18 -0
- data/lib/pleiades/core/command/routing/reflection.rb +13 -0
- data/lib/pleiades/core/command/routing/result.rb +47 -0
- data/lib/pleiades/core/command/routing/route_refine.rb +49 -0
- data/lib/pleiades/core/command/routing/validator.rb +72 -0
- data/lib/pleiades/core/command/routing_proxy.rb +126 -0
- data/lib/pleiades/core/config.rb +24 -17
- data/lib/pleiades/core/constants.rb +10 -7
- data/lib/pleiades/core/util.rb +9 -7
- data/lib/pleiades/core_ext/line/bot/event/base.rb +16 -7
- data/lib/pleiades/core_ext/line/bot/event/postback.rb +6 -4
- data/lib/pleiades/generators/pleiades/command/command_generator.rb +58 -51
- data/lib/pleiades/generators/pleiades/install/install_generator.rb +11 -12
- data/lib/pleiades/generators/pleiades/install/templates/config.yml +11 -1
- data/lib/pleiades/generators/pleiades/install/templates/pleiades.rb +1 -0
- data/lib/pleiades/generators/pleiades/install/templates/routing_proxy.rb +13 -0
- data/lib/pleiades/generators/pleiades/setup/setup_generator.rb +100 -98
- data/lib/pleiades/generators/pleiades/setup/templates/api_controller.rb +4 -15
- data/lib/pleiades/generators/pleiades/setup/templates/base_command.rb +2 -6
- data/lib/pleiades/generators/pleiades/setup/templates/command_common.erb +2 -6
- data/lib/pleiades/railtie.rb +3 -11
- data/lib/pleiades/version.rb +1 -1
- data/pleiades.gemspec +1 -0
- metadata +32 -8
- data/lib/pleiades/core/.keep +0 -0
- data/lib/pleiades/core/command/event_proccessor.rb +0 -87
- data/lib/pleiades/core/command/nest_blocks.rb +0 -55
- data/lib/pleiades/core_ext/.keep +0 -0
data/lib/pleiades/core/config.rb
CHANGED
@@ -5,25 +5,17 @@ module Pleiades
|
|
5
5
|
class Config
|
6
6
|
class << self
|
7
7
|
def configration
|
8
|
-
return nil if loaded?
|
9
|
-
|
10
8
|
@config = new(load).freeze
|
11
|
-
@loaded = true
|
12
|
-
end
|
13
|
-
|
14
|
-
def loaded?
|
15
|
-
@loaded
|
16
9
|
end
|
17
10
|
|
18
|
-
def method_missing
|
19
|
-
|
20
|
-
return super unless instance_methods.include?(method)
|
11
|
+
def method_missing(method, *_)
|
12
|
+
return super unless @config.respond_to?(method)
|
21
13
|
|
22
14
|
@config.__send__ method
|
23
15
|
end
|
24
16
|
|
25
|
-
def respond_to_missing?
|
26
|
-
|
17
|
+
def respond_to_missing?(_mes, *_)
|
18
|
+
true
|
27
19
|
end
|
28
20
|
|
29
21
|
private
|
@@ -33,20 +25,35 @@ module Pleiades
|
|
33
25
|
end
|
34
26
|
end
|
35
27
|
|
36
|
-
def
|
37
|
-
@src.
|
28
|
+
def router_default_option
|
29
|
+
@src.router.default.symbolize_keys
|
38
30
|
end
|
39
31
|
|
40
|
-
def
|
41
|
-
@src
|
32
|
+
def client_keys
|
33
|
+
@src
|
34
|
+
.client
|
35
|
+
.key_acquisition_process
|
36
|
+
.each_pair.map do |_, str_proc|
|
37
|
+
instance_eval(str_proc)
|
38
|
+
end
|
42
39
|
end
|
43
40
|
|
44
41
|
private
|
45
42
|
|
46
43
|
attr_reader :src
|
47
44
|
|
48
|
-
def initialize
|
45
|
+
def initialize(src)
|
49
46
|
@src = Pleiades::Util.define_reader src
|
50
47
|
end
|
48
|
+
|
49
|
+
def method_missing(method, *_)
|
50
|
+
@src.respond_to?(method) || super
|
51
|
+
|
52
|
+
@src.__send__ method
|
53
|
+
end
|
54
|
+
|
55
|
+
def respond_to_missing?(method, *_)
|
56
|
+
@src.respond_to?(method)
|
57
|
+
end
|
51
58
|
end
|
52
59
|
end
|
@@ -1,19 +1,22 @@
|
|
1
1
|
module Pleiades
|
2
2
|
module Constants
|
3
3
|
module Events
|
4
|
-
TYPES =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
TYPES =
|
5
|
+
%w[
|
6
|
+
text
|
7
|
+
sticker
|
8
|
+
postback
|
9
|
+
follow
|
10
|
+
unfollow
|
11
|
+
].map(&:freeze).freeze
|
11
12
|
end
|
12
13
|
|
13
14
|
module File
|
14
15
|
CONFIG_DIR_PATH = 'config/pleiades'.freeze
|
15
16
|
CONFIG = "#{CONFIG_DIR_PATH}/config.yml".freeze
|
17
|
+
INITIALIZER = 'config/initializers/pleiades.rb'.freeze
|
16
18
|
ROUTER = "#{CONFIG_DIR_PATH}/router.rb".freeze
|
19
|
+
ROUTING_PROXY = "#{CONFIG_DIR_PATH}/routing_proxy.rb".freeze
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/pleiades/core/util.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Pleiades
|
4
|
-
|
5
4
|
# Util Modules.
|
6
5
|
module Util
|
7
6
|
class << self
|
8
7
|
def define_reader(hash)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
hash.instance_eval do
|
9
|
+
hash.each_pair do |key, val|
|
10
|
+
l_val = val.is_a?(Hash) ? Pleiades::Util.define_reader(val) : val
|
11
|
+
define_singleton_method(key.to_s.underscore.to_sym) do
|
12
|
+
l_val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
hash
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'pleiades/core/util'
|
2
|
+
require 'freeezer'
|
2
3
|
|
3
4
|
module Line
|
4
5
|
module Bot
|
5
6
|
module Event
|
6
7
|
class Base
|
7
|
-
|
8
|
+
using Freeezer
|
9
|
+
|
10
|
+
def initialize(src)
|
8
11
|
@src = Pleiades::Util.define_reader src
|
9
12
|
|
13
|
+
# moduleにする
|
10
14
|
# /^[a-z]+_event\?$/
|
11
15
|
# => トークタイプの判定メソッドに反応する。
|
12
16
|
#
|
@@ -17,16 +21,21 @@ module Line
|
|
17
21
|
#
|
18
22
|
@src.define_singleton_method(:method_missing) do |method, *_|
|
19
23
|
return super() unless /^[a-z]+_event\?$/ =~ method
|
24
|
+
|
20
25
|
source.type == method.to_s.split('_').first
|
21
26
|
end
|
27
|
+
@src.deep_freeze
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
def method_missing(method, *_)
|
33
|
+
@src.respond_to?(method) || super
|
34
|
+
@src.__send__ method
|
35
|
+
end
|
36
|
+
|
37
|
+
def respond_to_missing?(method, *_)
|
38
|
+
@src.respond_to?(method) || super
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
@@ -4,7 +4,7 @@ module Line
|
|
4
4
|
class Postback
|
5
5
|
attr_reader :action, :params
|
6
6
|
|
7
|
-
def initialize
|
7
|
+
def initialize(src)
|
8
8
|
super
|
9
9
|
set_instance_variables
|
10
10
|
end
|
@@ -16,9 +16,11 @@ module Line
|
|
16
16
|
# action 'path/to/command'
|
17
17
|
# params '{product_id: 1, order_num: 3}'
|
18
18
|
def set_instance_variables
|
19
|
-
data =
|
20
|
-
|
21
|
-
|
19
|
+
data =
|
20
|
+
postback.data
|
21
|
+
.split('&')
|
22
|
+
.map { |s| s.split('=') }
|
23
|
+
.each_with_object({}) { |(key, val), hash| hash[key.to_sym] = val }
|
22
24
|
|
23
25
|
@action = data.delete :action
|
24
26
|
@params = data
|
@@ -1,68 +1,75 @@
|
|
1
1
|
require 'pleiades/core/constants'
|
2
2
|
require 'pleiades/core/config'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
class CommandGenerator < Rails::Generators::NamedBase
|
7
|
-
source_root File.expand_path('templates', __dir__)
|
4
|
+
class Pleiades::CommandGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
8
6
|
|
9
|
-
|
7
|
+
argument :names, type: :array, desc: 'Specify command class name.'
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
dir_options =
|
10
|
+
{
|
11
|
+
aliases: '-d',
|
12
|
+
desc: 'Specify the directory to generate commands.'
|
13
|
+
}
|
14
|
+
class_option :dir, dir_options
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
event_type_options =
|
17
|
+
{
|
18
|
+
aliases: '-t',
|
19
|
+
desc: 'Specify command type.',
|
20
|
+
default: :text,
|
21
|
+
enum: Pleiades::Constants::Events::TYPES
|
22
|
+
}
|
23
|
+
class_option :event_type, event_type_options
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
25
|
+
def setup
|
26
|
+
@names.unshift @name
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
def generate_command
|
30
|
+
commands_path = Pleiades::Config.command.commands_path
|
31
|
+
@names.each do |name|
|
32
|
+
template 'command.erb', "#{commands_path}/#{options['dir']}/#{name}.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def drow_route
|
37
|
+
@names.each do |name|
|
38
|
+
arg =
|
39
|
+
[
|
40
|
+
Pleiades::Constants::File::ROUTER,
|
41
|
+
event_with_option(name),
|
42
|
+
{ after: /^Pleiades::Command::Router.route do/ }
|
43
|
+
]
|
44
|
+
inject_into_file(*arg)
|
45
|
+
end
|
46
|
+
end
|
39
47
|
|
40
|
-
|
48
|
+
private
|
41
49
|
|
42
|
-
|
43
|
-
|
50
|
+
def event_with_option(name)
|
51
|
+
option = event_specific_options
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
str = "\n #{options['event_type']}"
|
54
|
+
str += " action: '#{name}'"
|
55
|
+
str += ", scope: '#{options['dir']}'" if options['dir']
|
56
|
+
str += ", #{option}" if option
|
48
57
|
|
49
|
-
|
50
|
-
|
58
|
+
str
|
59
|
+
end
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
61
|
+
def event_specific_options
|
62
|
+
EventOption.const_get options['event_type'].capitalize
|
63
|
+
rescue NameError => _e
|
64
|
+
nil
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
def dirs
|
68
|
+
options['dir'].split('/')
|
69
|
+
end
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
71
|
+
module EventOption
|
72
|
+
Text = 'pattern: //'.freeze
|
73
|
+
Sticker = 'package_id: 1, sticker_id: 1'.freeze
|
67
74
|
end
|
68
75
|
end
|
@@ -1,16 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('templates', __dir__)
|
1
|
+
class Pleiades::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
def generate_file
|
5
|
+
cst = Pleiades::Constants::File
|
6
|
+
file_paths =
|
7
|
+
%W[
|
8
|
+
#{cst::CONFIG}
|
9
|
+
#{cst::INITIALIZER}
|
10
|
+
#{cst::ROUTER}
|
11
|
+
]
|
11
12
|
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
13
|
+
file_paths.each { |f| copy_file File.basename(f), f }
|
15
14
|
end
|
16
15
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
command:
|
2
|
-
commands_path:
|
2
|
+
commands_path: app/commands
|
3
|
+
default: base_command
|
4
|
+
router:
|
5
|
+
default:
|
6
|
+
method: call
|
7
|
+
concern: []
|
8
|
+
executor: Pleiades::Command::Executor
|
9
|
+
client:
|
10
|
+
key_acquisition_process:
|
11
|
+
channel_secret: ENV["LINE_CHANNEL_SECRET"]
|
12
|
+
channel_token : ENV["LINE_CHANNEL_TOKEN"]
|
3
13
|
debug:
|
4
14
|
# call BaseCommand#show_event
|
5
15
|
disp_console: true
|
@@ -0,0 +1 @@
|
|
1
|
+
Pleiades::Config.configration
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Pleiades::Command::RoutingProxy.routing do
|
2
|
+
#
|
3
|
+
# EXAMPLE
|
4
|
+
# if @event.source.user_id == 'Udeadbeefdeadbeefdeadbeefdeadbeef'
|
5
|
+
# mount line: 'config/pleiades/line'
|
6
|
+
# add 'line_dev', mnt: :line
|
7
|
+
# # => load by 'config/pleiades/line/line_dev.rb'
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
|
11
|
+
# only load by 'config/pleiades/router.rb'.
|
12
|
+
default_routing
|
13
|
+
end
|
@@ -1,125 +1,127 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
class Pleiades::SetupGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
exe_user_options =
|
5
|
+
{
|
6
|
+
aliases: '-u',
|
7
|
+
type: :boolean,
|
8
|
+
desc: 'Execute generate migration:user & user_related_commands'
|
9
|
+
}
|
10
|
+
class_option :user_related_files, exe_user_options
|
11
|
+
|
12
|
+
def gen_user_related_files
|
13
|
+
return unless options['user_related_files']
|
14
|
+
|
15
|
+
gen_user_table unless user_table_exist?
|
16
|
+
gen_users_command unless users_command_exist?
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
def gen_base_command
|
20
|
+
return if base_command_exist?
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
copy_file File.basename(command_file_path), command_file_path
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
def gen_command_concern
|
26
|
+
return if command_concern_exist?
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
template File.basename(command_concern_path('e')), command_concern_path
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
def gen_controller
|
32
|
+
return if controller_file_exist?
|
34
33
|
|
35
|
-
|
34
|
+
generate 'controller', controller_dir
|
36
35
|
|
37
|
-
|
38
|
-
namespace :line do
|
39
|
-
namespace :api do
|
40
|
-
post '/' , action: 'callback'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
EOF
|
44
|
-
File.delete controller_file_path
|
45
|
-
copy_file File.basename(controller_file_path), controller_file_path
|
46
|
-
end
|
36
|
+
route routes_drowing_str
|
47
37
|
|
48
|
-
|
38
|
+
File.delete controller_file_path
|
39
|
+
copy_file File.basename(controller_file_path), controller_file_path
|
40
|
+
end
|
49
41
|
|
50
|
-
|
51
|
-
method_name = /^(([a-z]+_)+)exist\?$/.match(method.to_s)
|
52
|
-
return super unless method_name
|
42
|
+
private
|
53
43
|
|
54
|
-
|
55
|
-
|
44
|
+
def method_missing(method, *_)
|
45
|
+
method_name = /^(([a-z]+_)+)exist\?$/.match(method.to_s)
|
46
|
+
return super unless method_name
|
56
47
|
|
57
|
-
|
58
|
-
|
59
|
-
generate 'model', "user #{migration_arguments}"
|
48
|
+
File.exist? method(:"#{method_name[1]}path").call
|
49
|
+
end
|
60
50
|
|
61
|
-
|
62
|
-
|
51
|
+
# UserModelのマイグレーションファイル生成
|
52
|
+
def gen_user_table
|
53
|
+
generate 'model', "user #{migration_arguments}"
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
", #{val[:options]}",
|
67
|
-
after: key
|
68
|
-
)
|
69
|
-
end
|
70
|
-
end
|
55
|
+
user_schemas.each_pair do |key, val|
|
56
|
+
next unless val[:options]
|
71
57
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
58
|
+
inject_into_file(
|
59
|
+
migration_file_path,
|
60
|
+
", #{val[:options]}",
|
61
|
+
after: key
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
76
65
|
|
77
|
-
|
78
|
-
|
66
|
+
# ユーザに関するコマンドの生成
|
67
|
+
def gen_users_command
|
68
|
+
dir = 'users'
|
69
|
+
command_events = %w[follow unfollow]
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
.each_pair
|
83
|
-
.inject('') { |str, (key, val)| "#{str}#{key}:#{val[:type]} " }
|
84
|
-
end
|
71
|
+
command_events.each { |event| generate 'pleiades:command', "#{event} -d #{dir} -t #{event}" }
|
72
|
+
end
|
85
73
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
}
|
92
|
-
end
|
74
|
+
def migration_arguments
|
75
|
+
user_schemas
|
76
|
+
.each_pair
|
77
|
+
.inject('') { |str, (key, val)| "#{str}#{key}:#{val[:type]} " }
|
78
|
+
end
|
93
79
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
80
|
+
def user_schemas
|
81
|
+
{
|
82
|
+
line_id: { type: :string, options: 'null: false, unique: true' },
|
83
|
+
unsubscrided: { type: :boolean },
|
84
|
+
unsubscrided_at: { type: :datetime }
|
85
|
+
}
|
86
|
+
end
|
98
87
|
|
99
|
-
|
100
|
-
|
101
|
-
|
88
|
+
def user_table_path
|
89
|
+
path = Dir.glob(migration_file_path).first
|
90
|
+
path || migration_file_path
|
91
|
+
end
|
102
92
|
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
def migration_file_path
|
94
|
+
'db/migrate/*_users.rb'
|
95
|
+
end
|
106
96
|
|
107
|
-
|
108
|
-
|
109
|
-
|
97
|
+
def users_command_path
|
98
|
+
"#{Pleiades::Config.command.commands_path}/users/follow.rb"
|
99
|
+
end
|
110
100
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
101
|
+
def base_command_path
|
102
|
+
"#{Pleiades::Config.command.commands_path}/base_command.rb"
|
103
|
+
end
|
115
104
|
|
116
|
-
|
117
|
-
|
118
|
-
|
105
|
+
def command_concern_path(add_ext = false)
|
106
|
+
ext = add_ext ? true.to_s[3] : ''
|
107
|
+
"#{Pleiades::Config.command.commands_path}/concerns/command_common.#{ext}rb"
|
108
|
+
end
|
109
|
+
|
110
|
+
def controller_file_path
|
111
|
+
"app/controllers/#{controller_dir}_controller.rb"
|
112
|
+
end
|
119
113
|
|
120
|
-
|
121
|
-
|
114
|
+
def controller_dir
|
115
|
+
'line/api'
|
116
|
+
end
|
117
|
+
|
118
|
+
def routes_drowing_str
|
119
|
+
<<~ROUTE
|
120
|
+
namespace :line do
|
121
|
+
namespace :api do
|
122
|
+
post '/' , action: 'callback'
|
123
|
+
end
|
122
124
|
end
|
123
|
-
|
125
|
+
ROUTE
|
124
126
|
end
|
125
127
|
end
|