safeword 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 744d30f815ed87f46a56511eea26c89f36a71d83
4
- data.tar.gz: d8aab455c16f68cd2f0b563c782d814b09a09db6
3
+ metadata.gz: fdcc5aab7e93a02b4b28b779825285981514916d
4
+ data.tar.gz: 375d1ffacd53c00444905b906832537f0fd0894c
5
5
  SHA512:
6
- metadata.gz: 19d44c5fb2d7ba942ded9f277d9cd3879000f9a75f45c0e04e2d6b4de01bfc3d75e5e46432c0a349f190957756d1b5786dfd88fe983f701f2f8b939fbf8d4008
7
- data.tar.gz: 972b5aa3e02ccb38b1b429b15e92234aa4c6e28e2838807092b4a14b4a78b76bb3ac1ea8ac4e1448a342a3e4a0e1382faff0867b9ac97903bad04b72f7adea2d
6
+ metadata.gz: ac38a9a168cb32e396c93bea87e9b0f93265c8b259c6d0e67e445fef44f18d8aaf45a334acc4b42facd0e1b2ed089c812cd76bdeaf7b0a3b18bf723bc2bf47d0
7
+ data.tar.gz: de96362b1ea67321be8c3d7a4a922efe6c217dc36e008114d3d99d7779d8a65c9d032ca410c9f8755321d0a081d992774383c3dd2bbc13413104332d1dbf9ab1
data/README.md CHANGED
@@ -40,7 +40,7 @@ safeword.enable
40
40
  safeword.enabled? # => true
41
41
  ```
42
42
 
43
- ### Preventing code from running
43
+ ### Preventing code execution
44
44
 
45
45
  Instantiate a `Safeword` and pass your wrapped code in a block to its `use` method.
46
46
 
@@ -49,10 +49,32 @@ require 'safeword'
49
49
 
50
50
  safeword = Safeword.new
51
51
  safeword.use { puts 'start war' } #=> nothing happens
52
+ ```
53
+
54
+ ### Allowing code execution
55
+ Call `#disable` on the safeword to allow subsequent calls to `use` to execute the provided code blocks:
56
+
57
+ ```ruby
58
+ require 'safeword'
59
+
60
+ safeword = Safeword.new
52
61
  safeword.disable
53
62
  safeword.use { puts 'drop bomb' } #=> drop bomb
54
63
  ```
55
64
 
65
+ ### Instantiating a disabled safeword
66
+ Safewords are enabled by default, but can be disabled during initialization:
67
+
68
+ ```ruby
69
+ require 'safeword'
70
+
71
+ safe = Safeword.new
72
+ safe.enabled? #=> true
73
+
74
+ unsafe = Safeword.new(enabled: false)
75
+ unsafe.enabled? #=> false
76
+ ```
77
+
56
78
  ### Chaining methods
57
79
 
58
80
  The methods `enable`, `disable` and `use` return the word itself, so you can chain multiple calls together:
data/lib/safeword.rb CHANGED
@@ -4,7 +4,7 @@ require 'safeword/blocker'
4
4
  # Encapsulates the logic of the gem.
5
5
  module Safeword
6
6
  # Instantiates a +Blocker+.
7
- def self.new
8
- Blocker.new
7
+ def self.new(enabled: true)
8
+ Blocker.new(enabled: enabled)
9
9
  end
10
10
  end
@@ -1,29 +1,62 @@
1
1
  module Safeword
2
2
  # Decides whether blocks of code are executed or not.
3
3
  class Blocker
4
+ #
4
5
  # Instantiates an enabled blocker.
5
- def initialize
6
- @enabled = true
6
+ #
7
+ # @param [Boolean] enabled Whether the blocker is enabled or not.
8
+ def initialize(enabled: true)
9
+ @enabled = enabled
7
10
  end
8
11
 
9
12
  # Whether the blocker is enabled or not. Enabled blockers prevent blocks of code from being executed.
13
+ #
14
+ # @example Verifying if a blocker is enabled
15
+ # blocker.enable
16
+ # blocker.enabled? #=> true
17
+ # blocker.disable
18
+ # blocker.enabled? #=> false
19
+ #
20
+ # @return +true+ if the blocker is enabled, +false+ otherwise.
10
21
  def enabled?
11
22
  @enabled
12
23
  end
13
24
 
14
25
  # Enables the blocker, preventing blocks of code from being executed.
26
+ #
27
+ # @example Enabling a blocker
28
+ # blocker.enable
29
+ # blocker.use { puts 'I wont be executed' } #=> nothing happens
30
+ #
31
+ # @return +self+
15
32
  def enable
16
33
  @enabled = true
17
34
  self
18
35
  end
19
36
 
20
37
  # Disables the blocker, allowing blocks of code to be executed.
38
+ #
39
+ # @example Disabling a blocker
40
+ # blocker.disable
41
+ # blocker.use { puts 'I will be executed' } #=> I will be executed
42
+ #
43
+ # @return +self+
21
44
  def disable
22
45
  @enabled = false
23
46
  self
24
47
  end
25
48
 
26
49
  # Ignores the provided block of code if enabled. Executes it otherwise.
50
+ #
51
+ # @example Ignoring a block of code when enabled
52
+ # blocker.enable
53
+ # blocker.use { puts 'I wont be executed' } #=> nothing happens
54
+ #
55
+ # @example Executing a block of code when disabled
56
+ # blocker.disable
57
+ # blocker.use { puts 'I will be executed' } #=> I will be executed
58
+ #
59
+ # @return +self+
27
60
  def use
28
61
  yield unless enabled?
29
62
  self
@@ -1,3 +1,3 @@
1
1
  module Safeword
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safeword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler