wideopenspaces-wicked 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION.yml +2 -2
  2. data/lib/wicked.rb +42 -28
  3. metadata +29 -10
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 0
2
+ :minor: 3
3
+ :patch: 1
4
4
  :major: 0
data/lib/wicked.rb CHANGED
@@ -7,63 +7,77 @@ module Wicked
7
7
  # Got it? Wicked Good!
8
8
  module Good
9
9
 
10
- # Aliases for 'andand'
11
- # if phone = user.et.number; .... ; end
10
+ # Alias for 'andand' that reads like 'if user and number'
11
+ # if user.et.number...
12
12
  alias_method :et, :andand # Latin for 'and'
13
13
 
14
- # if phone = user.ask.number ....
14
+ # Alias for 'andand' that reads like 'if user, ask its number'
15
+ # if user.ask.number...
15
16
  alias_method :ask, :andand
16
17
 
17
18
  # Alias for andand that's meaningful when checking booleans;
18
19
  # this is the positive version of aint.
19
20
  # "don't fix it" unless it.is.broken?
20
- # Returns nil if 'it' is broken, so this is safer than:
21
- # "don't fix it" unless it.broken?
22
- alias_method :is, :andand
21
+ alias_method :is, :andand
22
+
23
+ # :nodoc:
24
+ alias_method :aintnot, :andand
23
25
 
24
26
  # Guarded method negation in the style of andand
25
27
  # Returns the logical opposite of the method invoked on the receiver
26
- # receiver.aint.method
27
- # Traps NoMethodError and returns nil if receiver is nil
28
- # or the method does not exist on the receiver.
28
+ # Returns nil if receiver is nil or doesn't have method.
29
29
  #
30
- # [].aint.empty?
31
- # => false
32
- # [].aint.nil?
33
- # => true
34
- # it.aint.broken?
35
- # => false
30
+ # [].aint.empty? => false
31
+ # [].aint.nil? => true
32
+ # it.aint.broken? => false
36
33
  #
37
- # Don't be a doofus, use this wisely, on boolean methods only
38
- # if you know what's good for you.
39
-
34
+ # Don't be a doofus, use this wisely, on boolean methods only if you know what's good for you.
40
35
  def aint(p = nil)
41
36
  NotReturningMe.new(self)
42
37
  end
43
38
 
44
39
  # A funny byproduct of using aint...
45
- # But before you get confused, read it as 'is not nothing, which should be true except for nil)
40
+ # nil.aint_nothin? => false
46
41
  def aint_nothin?
47
42
  self.aint.nil?
48
43
  end
49
- # See? You can laugh...
50
44
  alias_method :aint_it_somethin?, :aint_nothin?
51
45
 
52
- # Ok, so here goes - true if nothing, like nil
46
+ # nil.is_nothin? => true
53
47
  def is_nothin?
54
48
  !self.is.nil?
55
49
  end
56
50
 
57
- # A few stylistic variations on aint
51
+ # A few stylistic variations on aint for the grammatically uncreative ;)
52
+ # --
53
+ # 'andnot' is probably the closest analogue to 'andand' (and Ruby's
54
+ # syntax - && !), unless you want to write out 'andandnot' :)
55
+ alias_method :andnot, :aint
56
+
58
57
  alias_method :isnt, :aint
59
58
  alias_method :is_not, :aint
60
- alias_method :notnot, :aint
59
+ # Removed #notnot in favor of #andnot
60
+
61
+ # Just in case you can't keep your fingers off the Gs
62
+ alias_method :aint_nothing?, :aint_nothin?
63
+ alias_method :is_nothing?, :is_nothin?
61
64
 
62
- # Hehe
63
- alias_method :aintnot, :andand
64
- # As in 'User, eh? Wot's yer number?'
65
- # if phone = user.eh?.number; .... ; end
66
- alias_method :eh?, :andand
65
+
66
+
67
+ # Are you reading my notes? Well, cool!
68
+ # I wrote this for my personal site -- jacob-stetser.com -- and thought
69
+ # it might be useful to other people, so I extracted it!
70
+
71
+ # Here's a few real-world uses:
72
+ # [Create or find a user, assign to 'user' and check if new record all in one line]
73
+ # if (user = User.find_or_initialize_by_email(self.author_email)).is.new_record? ... end
74
+ #
75
+ # [Safely simplify chained expressions] from:
76
+ # if @current_user and role = @current_user.role and role.admin?
77
+ # to:
78
+ # if @current_user.ask.role.is.admin?
79
+ #
80
+ # Wicked Sweet. Ciao!
67
81
  end
68
82
 
69
83
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wideopenspaces-wicked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jacob Stetser
@@ -9,18 +15,24 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-02-01 00:00:00 -08:00
13
- default_executable:
18
+ date: 2009-02-01 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: andand
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
19
25
  requirements:
20
26
  - - ">="
21
27
  - !ruby/object:Gem::Version
28
+ hash: 25
29
+ segments:
30
+ - 1
31
+ - 3
32
+ - 1
22
33
  version: 1.3.1
23
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
24
36
  description: "Wicked Good extensions to Object in the vein of #andand"
25
37
  email: jake@wideopenspac.es
26
38
  executables: []
@@ -34,8 +46,9 @@ files:
34
46
  - lib/wicked.rb
35
47
  - test/test_helper.rb
36
48
  - test/wicked_test.rb
37
- has_rdoc: true
38
49
  homepage: http://github.com/wideopenspaces/wicked
50
+ licenses: []
51
+
39
52
  post_install_message:
40
53
  rdoc_options:
41
54
  - --inline-source
@@ -43,21 +56,27 @@ rdoc_options:
43
56
  require_paths:
44
57
  - lib
45
58
  required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
46
60
  requirements:
47
61
  - - ">="
48
62
  - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
49
66
  version: "0"
50
- version:
51
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
52
69
  requirements:
53
70
  - - ">="
54
71
  - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
55
75
  version: "0"
56
- version:
57
76
  requirements: []
58
77
 
59
78
  rubyforge_project:
60
- rubygems_version: 1.2.0
79
+ rubygems_version: 1.7.2
61
80
  signing_key:
62
81
  specification_version: 2
63
82
  summary: "Wicked Good extensions to Object in the vein of #andand"