Class: OceanWechatRobot::Command
- Inherits:
-
CLAide::Command
- Object
- CLAide::Command
- OceanWechatRobot::Command
- Defined in:
- lib/ocean_wechat_robot/command.rb
Class Method Summary collapse
-
.options ⇒ Object
参数选项.
-
.run(argv) ⇒ Object
1 运行入口,这里可以坐一些初始化,其他的依赖校验,比如 git 版本等等.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Command
constructor
2 初始化.
-
#run ⇒ Object
3 重写父类run,执行逻辑,不需要调用 super.
-
#validate! ⇒ Object
3 参数校验.
Constructor Details
#initialize(argv) ⇒ Command
2
初始化
34 35 36 37 38 39 40 |
# File 'lib/ocean_wechat_robot/command.rb', line 34 def initialize(argv) super @webhook = argv.option('webhook') @msg = argv.option('msg') @msg_type = argv.option('msg-type') @at_mobiles = argv.option("at-mobiles", "").split(",") end |
Class Method Details
.options ⇒ Object
参数选项
15 16 17 18 19 20 21 22 |
# File 'lib/ocean_wechat_robot/command.rb', line 15 def self. [ ['--webhook=wechat group webhook', '微信群的webhook'], ['--msg=content', '微信群消息'], ['--msg-type=[text|markdown|news]', '微信群消息的类型'], ['--at-mobiles=phone', '@人的手机号,多个用,分割'], ].concat(super) end |
.run(argv) ⇒ Object
1
运行入口,这里可以坐一些初始化,其他的依赖校验,比如 git 版本等等
27 28 29 |
# File 'lib/ocean_wechat_robot/command.rb', line 27 def self.run(argv) super(argv) end |
Instance Method Details
#run ⇒ Object
3
重写父类run,执行逻辑,不需要调用 super
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ocean_wechat_robot/command.rb', line 66 def run wechat = OceanWechatRobot::WechatRobot.new("#{@webhook}") if @msg_type == 'text' wechat.send_text(@msg, @at_mobiles) elsif @msg_type == 'markdown' wechat.send_markdown(@msg, @at_mobiles) elsif @msg_type == 'news' # wechat.send_news('', '', '', '', @at_mobiles) raise 'news 类型未实现......' end end |
#validate! ⇒ Object
3
参数校验
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ocean_wechat_robot/command.rb', line 44 def validate! super unless @webhook help!('please set webhook value!') end unless @msg help!('please set msg value!') end unless @msg_type help!('please set msg type value!') end if @msg_type && !%w(text markdown news).include?(@msg_type) help! "`#{@msg_type}' is not a valid msg type!" end end |