valim 0.0.3 → 0.0.4

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.
Files changed (3) hide show
  1. data/README.md +18 -1
  2. data/lib/valim.rb +16 -39
  3. metadata +3 -3
data/README.md CHANGED
@@ -2,4 +2,21 @@ Adds Valimisms to your ruby
2
2
 
3
3
  def code_is_awesome
4
4
  confirm
5
- end
5
+ end
6
+
7
+ For more advanced usage of valim, you might try:
8
+
9
+ class User < ActiveRecord::Base
10
+ # stuff here
11
+ end
12
+
13
+ (User.count > 5).confirm / deny? # => confirm
14
+
15
+ Don't be stupid
16
+
17
+ class User < ActiveRecord::Base
18
+ def have_at_least_x_users(x)
19
+ facepalm if x < 0
20
+ (count >= x).confirm / deny?
21
+ end
22
+ end
@@ -1,66 +1,43 @@
1
- module Kernel
2
- def confirm?
3
- true
4
- end
1
+ module Valim
2
+ class FacepalmError < StandardError ; end
5
3
 
6
- def deny?
7
- false
4
+ def have_doubts
5
+ !!yield
8
6
  end
7
+ extend self
8
+ end
9
9
 
10
+ module Kernel
10
11
  def confirm
11
12
  !!self
12
13
  end
14
+ alias :confirm? :confirm
13
15
 
14
16
  def deny
15
- false
17
+ !self
18
+ end
19
+ alias :deny? :deny
20
+
21
+ def / o
22
+ self
16
23
  end
17
24
 
18
25
  def confirm_deny?
19
26
  confirm?
20
27
  end
21
- end
22
-
23
- module Valim
24
- module Denied
25
- def confirm?
26
- false
27
- end
28
28
 
29
- def deny?
30
- true
31
- end
29
+ def facepalm
30
+ raise Valim::FacepalmError, "**facepalm**"
32
31
  end
33
32
  end
34
33
 
35
- class NilClass
36
- include Valim::Denied
37
- end
38
-
39
34
  class FalseClass
40
- include Valim::Denied
41
-
42
- def / o
43
- self
44
- end
45
-
46
- def inspect
47
- "deny"
48
- end
49
-
50
35
  def to_s
51
36
  "deny"
52
37
  end
53
38
  end
54
39
 
55
40
  class TrueClass
56
- def inspect
57
- "confirm"
58
- end
59
-
60
- def / o
61
- self
62
- end
63
-
64
41
  def to_s
65
42
  "confirm"
66
43
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valim
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl Lerche