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
@@ -1,25 +1,14 @@
|
|
1
1
|
require 'pleiades'
|
2
2
|
|
3
3
|
class Line::ApiController < ApplicationController
|
4
|
-
|
5
|
-
@client ||= Line::Bot::Client.new { |config|
|
6
|
-
config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
|
7
|
-
config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
|
8
|
-
}
|
9
|
-
end
|
4
|
+
include Pleiades::Client
|
10
5
|
|
11
6
|
def callback
|
12
|
-
|
13
|
-
|
14
|
-
signature = request.env['HTTP_X_LINE_SIGNATURE']
|
15
|
-
client.validate_signature(body, signature) || head(:bad_request)
|
16
|
-
|
17
|
-
events = client.parse_events_from(body)
|
7
|
+
validate_signature || head(:bad_request)
|
18
8
|
|
19
9
|
events.each do |event|
|
20
|
-
|
21
|
-
command.call
|
22
|
-
head :ok if command.success?
|
10
|
+
Pleiades::Command.get(event).call
|
23
11
|
end
|
12
|
+
head :ok
|
24
13
|
end
|
25
14
|
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
class BaseCommand < Pleiades::Command::BaseCommand
|
2
|
-
include CommandCommon
|
3
|
-
|
4
2
|
def call
|
5
3
|
success!
|
6
4
|
show_event if disp?
|
@@ -9,11 +7,11 @@ class BaseCommand < Pleiades::Command::BaseCommand
|
|
9
7
|
private
|
10
8
|
|
11
9
|
def disp?
|
12
|
-
Rails.env.development? && Pleiades::Config.disp_console
|
10
|
+
Rails.env.development? && Pleiades::Config.debug.disp_console
|
13
11
|
end
|
14
12
|
|
15
13
|
def show_event
|
16
|
-
|
14
|
+
p <<~MES
|
17
15
|
\n
|
18
16
|
\n
|
19
17
|
|------------------------------------|
|
@@ -22,7 +20,5 @@ class BaseCommand < Pleiades::Command::BaseCommand
|
|
22
20
|
\n
|
23
21
|
event:#{@event.type}
|
24
22
|
MES
|
25
|
-
|
26
|
-
p mes
|
27
23
|
end
|
28
24
|
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module CommandCommon
|
2
2
|
extend ActiveSupport::Concern
|
3
|
+
include Pleiades::Client
|
3
4
|
|
4
5
|
included do
|
5
|
-
|
6
|
-
@client ||= Line::Bot::Client.new { |config|
|
7
|
-
config.channel_secret = ENV['LINE_CHANNEL_SECRET']
|
8
|
-
config.channel_token = ENV['LINE_CHANNEL_TOKEN']
|
9
|
-
}
|
10
|
-
end<% if options['user_related_files'] %>
|
6
|
+
<% if options['user_related_files'] %>
|
11
7
|
|
12
8
|
def current_user
|
13
9
|
@user ||= User.find_by_line_id(@event.source.user_id)
|
data/lib/pleiades/railtie.rb
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
module Pleiades
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
generators do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
setup
|
8
|
-
command
|
9
|
-
)
|
10
|
-
|
11
|
-
generator_path = './generators/pleiades'.freeze
|
12
|
-
generator_names
|
13
|
-
.map { |f| "#{generator_path}/#{f}/#{f}_generator.rb" }
|
4
|
+
Dir
|
5
|
+
.glob("#{File.expand_path('generators/pleiades', __dir__)}/*")
|
6
|
+
.map { |f| "#{f}/#{File.basename(f)}_generator.rb" }
|
14
7
|
.each { |f| require_relative f }
|
15
|
-
|
16
8
|
end
|
17
9
|
end
|
18
10
|
end
|
data/lib/pleiades/version.rb
CHANGED
data/pleiades.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
28
|
spec.add_dependency 'bundler', '~> 2.0'
|
29
|
+
spec.add_dependency 'freeezer'
|
29
30
|
spec.add_dependency 'line-bot-api', '~> 1.12.0'
|
30
31
|
spec.add_development_dependency 'rails', '~> 5.2.3'
|
31
32
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pleiades
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HarukiKubota
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: freeezer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: line-bot-api
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,17 +113,26 @@ files:
|
|
99
113
|
- bin/setup
|
100
114
|
- lib/pleiades.rb
|
101
115
|
- lib/pleiades/core.rb
|
102
|
-
- lib/pleiades/core
|
116
|
+
- lib/pleiades/core/client.rb
|
117
|
+
- lib/pleiades/core/client/wrapper.rb
|
103
118
|
- lib/pleiades/core/command.rb
|
104
119
|
- lib/pleiades/core/command/base_command.rb
|
105
|
-
- lib/pleiades/core/command/
|
106
|
-
- lib/pleiades/core/command/
|
120
|
+
- lib/pleiades/core/command/executor.rb
|
121
|
+
- lib/pleiades/core/command/factory.rb
|
107
122
|
- lib/pleiades/core/command/router.rb
|
123
|
+
- lib/pleiades/core/command/routing/event_judge_methods.rb
|
124
|
+
- lib/pleiades/core/command/routing/event_proccessor.rb
|
125
|
+
- lib/pleiades/core/command/routing/nest_blocks.rb
|
126
|
+
- lib/pleiades/core/command/routing/path_builder.rb
|
127
|
+
- lib/pleiades/core/command/routing/reflection.rb
|
128
|
+
- lib/pleiades/core/command/routing/result.rb
|
129
|
+
- lib/pleiades/core/command/routing/route_refine.rb
|
130
|
+
- lib/pleiades/core/command/routing/validator.rb
|
131
|
+
- lib/pleiades/core/command/routing_proxy.rb
|
108
132
|
- lib/pleiades/core/config.rb
|
109
133
|
- lib/pleiades/core/constants.rb
|
110
134
|
- lib/pleiades/core/util.rb
|
111
135
|
- lib/pleiades/core_ext.rb
|
112
|
-
- lib/pleiades/core_ext/.keep
|
113
136
|
- lib/pleiades/core_ext/line/bot.rb
|
114
137
|
- lib/pleiades/core_ext/line/bot/event.rb
|
115
138
|
- lib/pleiades/core_ext/line/bot/event/base.rb
|
@@ -120,7 +143,9 @@ files:
|
|
120
143
|
- lib/pleiades/generators/pleiades/install/USAGE
|
121
144
|
- lib/pleiades/generators/pleiades/install/install_generator.rb
|
122
145
|
- lib/pleiades/generators/pleiades/install/templates/config.yml
|
146
|
+
- lib/pleiades/generators/pleiades/install/templates/pleiades.rb
|
123
147
|
- lib/pleiades/generators/pleiades/install/templates/router.rb
|
148
|
+
- lib/pleiades/generators/pleiades/install/templates/routing_proxy.rb
|
124
149
|
- lib/pleiades/generators/pleiades/setup/setup_generator.rb
|
125
150
|
- lib/pleiades/generators/pleiades/setup/templates/api_controller.rb
|
126
151
|
- lib/pleiades/generators/pleiades/setup/templates/base_command.rb
|
@@ -149,8 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
174
|
- !ruby/object:Gem::Version
|
150
175
|
version: '0'
|
151
176
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.7.6
|
177
|
+
rubygems_version: 3.0.3
|
154
178
|
signing_key:
|
155
179
|
specification_version: 4
|
156
180
|
summary: LINEBotSDKの拡張Gem。
|
data/lib/pleiades/core/.keep
DELETED
File without changes
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Pleiades
|
2
|
-
module Command
|
3
|
-
module EventProccessor
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
def method_missing(method, **args)
|
7
|
-
return super unless event_types.include?(method.to_s)
|
8
|
-
|
9
|
-
args.merge! type: method.to_s
|
10
|
-
|
11
|
-
exe_event_method args
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def event_types
|
17
|
-
Pleiades::Constants::Events::TYPES
|
18
|
-
end
|
19
|
-
|
20
|
-
def exe_event_method(args)
|
21
|
-
procs(args[:type]).each_with_object([true]) do |proc, arr|
|
22
|
-
next unless arr.last
|
23
|
-
|
24
|
-
arr << proc.call(args)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def procs(method_name)
|
29
|
-
proc_method_names = %i[
|
30
|
-
route_unfixid?
|
31
|
-
matching_events?
|
32
|
-
route_fix!
|
33
|
-
]
|
34
|
-
|
35
|
-
proc_method_names.insert(2, :"#{method_name}_judge_method") if judge_method_defined?(method_name)
|
36
|
-
proc_method_names.map { |n| method(n) }
|
37
|
-
end
|
38
|
-
|
39
|
-
def route_unfixid?(_args)
|
40
|
-
!Router.path_found?
|
41
|
-
end
|
42
|
-
|
43
|
-
def matching_events?(args)
|
44
|
-
@event.type == args[:type]
|
45
|
-
end
|
46
|
-
|
47
|
-
def route_fix!(args)
|
48
|
-
Router.path = normalize_path args[:scope], args[:action]
|
49
|
-
end
|
50
|
-
|
51
|
-
def judge_method_defined?(method)
|
52
|
-
private_methods.include?(:"#{method}_judge_method")
|
53
|
-
end
|
54
|
-
|
55
|
-
def text_judge_method(args)
|
56
|
-
decision_operator =
|
57
|
-
case args[:pattern]
|
58
|
-
when Regexp
|
59
|
-
'=~'
|
60
|
-
when String
|
61
|
-
'=='
|
62
|
-
end
|
63
|
-
eval("args[:pattern] #{decision_operator} @event.text")
|
64
|
-
end
|
65
|
-
|
66
|
-
def sticker_judge_method(args)
|
67
|
-
convert_to_reg = -> (id) do
|
68
|
-
case id
|
69
|
-
when String, Integer
|
70
|
-
return '*'.eql?(id) ? /^\d+$/ : /^#{id}$/
|
71
|
-
when Array
|
72
|
-
return /^#{id.join('|')}$/
|
73
|
-
end
|
74
|
-
id
|
75
|
-
end
|
76
|
-
|
77
|
-
p, s = @event.sticker_ids
|
78
|
-
convert_to_reg.(args[:package_id]) =~ p &&
|
79
|
-
convert_to_reg.(args[:sticker_id]) =~ s
|
80
|
-
end
|
81
|
-
|
82
|
-
def postback_judge_method(args)
|
83
|
-
normalize_path(args[:scope], args[:action]) == @event.action
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext'
|
2
|
-
|
3
|
-
module Pleiades
|
4
|
-
module Command
|
5
|
-
module NestBlocks
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
def scope(*scopes, &block)
|
9
|
-
scopes.each { |s| nest_block __callee__, s, &block }
|
10
|
-
end
|
11
|
-
alias :scope_append scope
|
12
|
-
alias :scope_unshift scope
|
13
|
-
|
14
|
-
def action(*actions, &block)
|
15
|
-
actions.each { |a| nest_block __callee__, a, &block }
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def default_options
|
21
|
-
{
|
22
|
-
scope: [],
|
23
|
-
action: ''
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
def nest_block(method, context, &block)
|
28
|
-
@_options = __send__ "merge_#{method}", context
|
29
|
-
Pleiades::Command::Router.new(@_options).instance_eval(&block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def merge_scope(context)
|
33
|
-
operator =
|
34
|
-
if /^merge_scope(_append)?$/ =~ __callee__
|
35
|
-
:append
|
36
|
-
elsif /^merge_scope_unshift$/ =~ __callee__
|
37
|
-
:unshift
|
38
|
-
end
|
39
|
-
__merge__ ->(option) { option[:scope].__send__ operator, context }
|
40
|
-
end
|
41
|
-
alias :merge_scope_append merge_scope
|
42
|
-
alias :merge_scope_unshift merge_scope
|
43
|
-
|
44
|
-
def merge_action(context)
|
45
|
-
__merge__ ->(option) { option[:action] = context }
|
46
|
-
end
|
47
|
-
|
48
|
-
def __merge__(proc)
|
49
|
-
dup_options = @options.deep_dup
|
50
|
-
proc.call(dup_options)
|
51
|
-
dup_options
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/pleiades/core_ext/.keep
DELETED
File without changes
|