isy 0.1.1 → 0.1.2

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: 1924fef98cb5aaaf39ed180fe2fd14db37bc072a
4
- data.tar.gz: 79661c9517afc68bf60dcb6db5f916249d633a6b
3
+ metadata.gz: 1550994168afbec25a7b84884bed12df5a820c7f
4
+ data.tar.gz: 4ae42990401ee896783e7faf287501d1f18e19d9
5
5
  SHA512:
6
- metadata.gz: 2192aa293532cfa148aaed6a2b54604a0505389ff77a7e2cafca582dbcc2bb0aeee3a8af0425786980d00930880ce136f1f5b7717b90f52e287b8a50c03cb3a6
7
- data.tar.gz: 89dba2c5ae9aa5bc706a30b4f2ed2057263118a6de96aa8a9711c258d03feaadb48351144ffb17c4ad9fa8f60e5badbdfc3a148276799d64d744109a8636bb22
6
+ metadata.gz: 9b3652ba2ea55251ab37446615bbc9a7233dc2566cafb2a4873c24ad001ae4d86e8ed3b1a9bf9d560b7f7afdf35fccfd3985968222d0586b796ecbd7edf941cb
7
+ data.tar.gz: 2a2efc241c027f5d8a6d9cef42c7cbbcfab9ea0aa09f94612faa71199b10504bb333a0071094c2dee33db66b1a281656bfd952f0e4234c9dedc96c1b9f9ed6d2
data/README.md CHANGED
@@ -9,8 +9,18 @@ def fullname segments=[]
9
9
  end
10
10
  ```
11
11
 
12
- Setting aside that an issue of this type can be a sign of an
13
- architectural problem, `isy` is meant to clean this up.
12
+ Setting aside that an issue of this type could be a sign of a greater
13
+ architectural problem, `Isy` takes a declarative approach to solving the problem.
14
+ Instead of dictating the contraints (and resulting response) to each argument type,
15
+ you can leverage Isy's simple interface:
16
+
17
+ ## Usage
18
+
19
+ The primary use of Isy is through the `isy` method, which is included into Object upon initialization
20
+
21
+ You can call isy from any point, but it's intended use is to be treated like a "guard clause" to
22
+ assert method argument types before those arguments are used (and potentially wreak havoc
23
+ throughout the implementation:
14
24
 
15
25
  ```ruby
16
26
  def fullname segments=[]
@@ -19,9 +29,25 @@ def fullname segments=[]
19
29
  end
20
30
  ```
21
31
 
22
- `Isy` takes a declarative approach to solving the problem. Instead of
23
- dictating the contraints (and resulting response) to each argument type,
24
- you can levelage Isy's simple interface.
32
+ The first argument is the subject of the test (i.e. what should match the proceeding assertion)
33
+ The second argument is the type.
34
+
35
+ If the subject doesn't match the provided type, then it raises a formatted exception describing
36
+ what argument *value* was a type mismatch (as an `Isy::ArgumentTypeMismatch` exception).
37
+
38
+ ## Usage with an operation
39
+
40
+ Optionally, in place of a type as the second argument, you can pass a block, and perform
41
+ a more complex comparison operation:
42
+
43
+ ```ruby
44
+ def fullname segments
45
+ isy segments { |seg| seg.length == 3 }
46
+ end
47
+ ```
48
+
49
+ As illustrated above, `isy` yields to the operation the first argument (segments). The expectation
50
+ is that the value returned by the operation (block) is a boolen (true => passes, false => failed).
25
51
 
26
52
  ## Performance
27
53
 
@@ -58,4 +84,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
58
84
 
59
85
  ## License
60
86
 
87
+ Copyright (c) 2016 Adam Cuppy, Zeal (https://codingzeal.com)
61
88
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,53 @@
1
+ require_relative 'exceptions'
2
+
3
+ module Isy
4
+ module Methods
5
+ # Isy::Methods#isy
6
+ #
7
+ # The primary use of Isy is through the #isy method, which is included into Object upon initialization
8
+ #
9
+ # == Usage
10
+ #
11
+ # You can call isy from any point, but it's intended use is to be treated like a "guard clause" to
12
+ # assert method argument types before those arguments are used (and potentially wreak havoc
13
+ # throughout the implementation:
14
+ #
15
+ # def fullname segments
16
+ # isy segments, Array
17
+ # end
18
+ #
19
+ # The first argument is the subject of the test (i.e. what should match the proceeding assertion)
20
+ # The second argument is the type.
21
+ #
22
+ # If the subject doesn't match the provided type, then it raises a formatted exception describing
23
+ # what argument _value_ was a type mismatch (as an `Isy::ArgumentTypeMismatch` exception).
24
+ #
25
+ # == Usage with an operation
26
+ #
27
+ # Optionally, in place of a type as the second argument, you can pass a block, and perform
28
+ # a more complex comparison operation:
29
+ #
30
+ # def fullname segments
31
+ # isy segments { |seg| seg.length == 3 }
32
+ # end
33
+ #
34
+ # As illustrated above, `isy` yields to the operation the first argument (segments). The expectation
35
+ # is that the value returned by the operation (block) is a boolen (true => passes, false => failed).
36
+ #
37
+ def isy subject, *args, &evaluation
38
+ if evaluation.nil? && args[0].nil?
39
+ raise ArgumentError,
40
+ 'Object#isy requires either a type or evaluation block'
41
+ end
42
+
43
+ evaluation ||= lambda { |s| s.is_a? args[0] }
44
+
45
+ unless evaluation.call(subject)
46
+ raise Isy::ArgumentTypeMismatch.new(
47
+ subject: subject,
48
+ caller_method: caller_locations(1,1)[0].label
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/isy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Isy
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/isy.rb CHANGED
@@ -1,30 +1,12 @@
1
- require "isy/version"
2
- require "isy/exceptions"
1
+ require 'isy/version'
2
+ require 'isy/methods'
3
3
 
4
4
  module Isy
5
- def self.bind!
5
+ def self.bind! # :nodoc:
6
6
  Object.instance_eval do
7
7
  include Isy::Methods
8
8
  end
9
9
  end
10
-
11
- module Methods
12
- def isy subject, *args, &evaluation
13
- if evaluation.nil? && args[0].nil?
14
- raise ArgumentError,
15
- 'Object#isy requires either a type or evaluation block'
16
- end
17
-
18
- evaluation ||= lambda { |s| s.is_a? args[0] }
19
-
20
- unless evaluation.call(subject)
21
- raise Isy::ArgumentTypeMismatch.new(
22
- subject: subject,
23
- caller_method: caller_locations(1,1)[0].label
24
- )
25
- end
26
- end
27
- end
28
10
  end
29
11
 
30
12
  Isy.bind!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cuppy
@@ -99,6 +99,7 @@ files:
99
99
  - isy.gemspec
100
100
  - lib/isy.rb
101
101
  - lib/isy/exceptions.rb
102
+ - lib/isy/methods.rb
102
103
  - lib/isy/version.rb
103
104
  homepage: https://github.com/acuppy/isy
104
105
  licenses: