slack_line 1.4 → 1.5
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/CHANGELOG.md +9 -0
- data/README.md +26 -1
- data/lib/slack_line/dsl_block.rb +48 -0
- data/lib/slack_line/message_context.rb +3 -1
- data/lib/slack_line/section_context.rb +3 -1
- data/lib/slack_line/thread_context.rb +3 -1
- data/lib/slack_line/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: efd923603f9c8c0a08e1c2111ef7d8a274f9ff100f793ce97032eeb46d06264c
|
|
4
|
+
data.tar.gz: 2fe6fb39012479adab7575215c85711fdda8d0e5acaa30baac2229936c5c596a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82be49510d54ac0e1aeefdcb89d6329516b2a169948fac6818508baedd6d44de0b9a9c8180c7c670380a635aa07672fab9f8d4cfed774bc4926fbeb79513718c
|
|
7
|
+
data.tar.gz: 44bdae493f5beb17941d8a0e1670bad815e6d3176bca3fba9d5eec4bd83805437ffec338fccd2044e16bdcdc1726751ed5472df8d119cbb969ddf2fbe930a31b
|
data/CHANGELOG.md
CHANGED
|
@@ -30,3 +30,12 @@ section block has one text field. Use one `section` per text.
|
|
|
30
30
|
|
|
31
31
|
Fixed README examples that didn't run, including `context` inside a `section`,
|
|
32
32
|
which Slack doesn't allow.
|
|
33
|
+
|
|
34
|
+
## Version 1.5
|
|
35
|
+
|
|
36
|
+
DSL blocks that take an argument now receive the builder, and `self` stays
|
|
37
|
+
the caller, so the block can use your own methods and instance variables:
|
|
38
|
+
`SlackLine.message { |m| m.text @title }`. Blocks with no arguments work as
|
|
39
|
+
before. When a bare block calls one of your own methods, SlackLine raises an
|
|
40
|
+
error that points at the block-argument form. It can't catch instance
|
|
41
|
+
variables, which are just nil inside a bare block.
|
data/README.md
CHANGED
|
@@ -18,7 +18,7 @@ msg = SlackLine.message do
|
|
|
18
18
|
# Like a Slack section block, a section holds one text and one link
|
|
19
19
|
section do
|
|
20
20
|
text "A thing has happened"
|
|
21
|
-
link "How bad?",
|
|
21
|
+
link "How bad?", "https://example.com/problems/1"
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
text "Yeah, it happened for sure"
|
|
@@ -58,6 +58,31 @@ sent_thread.detect { |m| m.content.to_s.include?("Not yet safe") }&.update do
|
|
|
58
58
|
end
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
### Blocks with an argument
|
|
62
|
+
|
|
63
|
+
A DSL block with no arguments runs with the builder as `self`, so you can
|
|
64
|
+
call `text`, `section` and the rest directly. That also means your own
|
|
65
|
+
instance variables and methods aren't available inside it, only locals.
|
|
66
|
+
|
|
67
|
+
If you need them, give the block an argument. SlackLine passes the builder
|
|
68
|
+
to it and leaves `self` alone. If a bare block calls one of your own
|
|
69
|
+
methods, SlackLine raises an error that says so. It can't do the same for
|
|
70
|
+
instance variables: `@problem` in a bare block is just nil, with no error.
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
class ProblemNotifier
|
|
74
|
+
def notify
|
|
75
|
+
SlackLine.message(to: "#ops") do |m|
|
|
76
|
+
m.text "Problem: #{@problem.title}"
|
|
77
|
+
m.section do |s|
|
|
78
|
+
s.text "A thing has happened"
|
|
79
|
+
s.link "How bad?", problems_path(@problem.id)
|
|
80
|
+
end
|
|
81
|
+
end.post
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
```
|
|
85
|
+
|
|
61
86
|
## Configuration
|
|
62
87
|
|
|
63
88
|
The only required setup is an OAuth token - each of these options can
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module SlackLine
|
|
2
|
+
# Runs a DSL block against a builder. A block that takes no arguments runs
|
|
3
|
+
# with the builder as self; a block that takes an argument receives the
|
|
4
|
+
# builder instead, so the caller keeps its own methods and instance variables.
|
|
5
|
+
#
|
|
6
|
+
# When a block with no arguments calls a method the builder lacks but the
|
|
7
|
+
# caller has, we raise an error that explains the block-argument form.
|
|
8
|
+
# We can't catch instance variables the same way: inside a bare block,
|
|
9
|
+
# @foo reads the builder's ivar, which is nil, and Ruby raises nothing.
|
|
10
|
+
module DslBlock
|
|
11
|
+
protected
|
|
12
|
+
|
|
13
|
+
attr_reader :dsl_caller
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def run_dsl_block(block)
|
|
18
|
+
return block.call(self) unless block.arity.zero?
|
|
19
|
+
|
|
20
|
+
@dsl_caller = find_dsl_caller(block)
|
|
21
|
+
instance_exec(&block)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A nested bare block's receiver is the outer builder, so ask it for the
|
|
25
|
+
# original caller instead.
|
|
26
|
+
def find_dsl_caller(block)
|
|
27
|
+
receiver = block.binding.receiver
|
|
28
|
+
receiver.is_a?(DslBlock) ? receiver.dsl_caller : receiver
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def method_missing(name, ...)
|
|
32
|
+
raise(NoMethodError.new(caller_method_message(name), name, receiver: self)) if dsl_caller&.respond_to?(name, true)
|
|
33
|
+
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def respond_to_missing?(name, include_private = false) = super
|
|
38
|
+
|
|
39
|
+
def caller_method_message(name)
|
|
40
|
+
<<~MSG.tr("\n", " ").strip
|
|
41
|
+
undefined method '#{name}' for #{self.class}. #{dsl_caller.class} defines '#{name}',
|
|
42
|
+
but a SlackLine block with no arguments runs with the builder as self, so
|
|
43
|
+
your own methods and instance variables aren't available inside it. Give the
|
|
44
|
+
block an argument to keep them, like `do |m| m.text ... end`.
|
|
45
|
+
MSG
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
module SlackLine
|
|
2
2
|
class SectionContext
|
|
3
|
+
include DslBlock
|
|
4
|
+
|
|
3
5
|
def initialize(parent_context, &block)
|
|
4
6
|
@content = parent_context.section do |s|
|
|
5
7
|
@in_progress_section = s
|
|
6
|
-
|
|
8
|
+
run_dsl_block(block)
|
|
7
9
|
ensure
|
|
8
10
|
@in_progress_section = nil
|
|
9
11
|
end
|
data/lib/slack_line/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack_line
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.5'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Mueller
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -216,6 +216,7 @@ files:
|
|
|
216
216
|
- lib/slack_line/client.rb
|
|
217
217
|
- lib/slack_line/configuration.rb
|
|
218
218
|
- lib/slack_line/disk_caching.rb
|
|
219
|
+
- lib/slack_line/dsl_block.rb
|
|
219
220
|
- lib/slack_line/groups.rb
|
|
220
221
|
- lib/slack_line/memoization.rb
|
|
221
222
|
- lib/slack_line/message.rb
|