bossy 0.0.4 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc3ed9df38c9d7c470ebd5e8eb68e6de1b52e501
4
- data.tar.gz: dd739f714eae9a6e022d78b961e10c36c0516869
3
+ metadata.gz: c47b19da9df1ee76c5afb78b067dd8887f651a1d
4
+ data.tar.gz: 6c90c4c8942e7fb4ec4638516634008a034a626b
5
5
  SHA512:
6
- metadata.gz: bd99784c4f4534b6268ee98843d87b30bbda05380afdd012ca70dc74f40d95e44dec9819918c9e91c461379e5377344b222b22a299dc0335ead26b5c4cbbd3de
7
- data.tar.gz: 7904f26b24c0d2928b6d27f61c674e496228374ba01b49f0efda144dedc4cef3b38ee828a2f1c48eeefa8b07ea8e85d07feb2e02f84cf097f938145fd36855c0
6
+ metadata.gz: 5569e6eb54fb22351f54d3f1053ae6584b1dbc56019d8a216e4ffd529ef2b211dedb263864ab9b6f2bd99d73ce653e7ba3a7c57a7afe60026f5790b059c6fe1f
7
+ data.tar.gz: fe2d5f1b0bb6b911797884d99b695d861c5cf6aff8007b1d53efe8ffde72af225cc219b31939d73716b1dd1733edf1492733e7d9aac8a18103259b5994ad1ca6
@@ -0,0 +1,14 @@
1
+ # These methods are what get added to any class that implements a Bossy
2
+ module Bossy::ClassMethods
3
+ def interface=(new_interface)
4
+ if @bossy_interface.nil?
5
+ @bossy_interface = new_interface
6
+ else # If we already have an interface, just add methods to it.
7
+ @bossy_interface.add_required_methods(new_interface.interface_methods)
8
+ end
9
+ end
10
+
11
+ def interface
12
+ @bossy_interface
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Bossy
2
+ module Errors
3
+ # Raised if a class or instance does not meet the interface requirements.
4
+ class MethodMissing < RuntimeError; end
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ module Bossy
2
+ class Interface
3
+ attr_accessor :klass, :interface_methods
4
+
5
+ def initialize(klass, required_methods)
6
+ @klass = klass
7
+ @interface_methods = []
8
+ add_required_methods(required_methods)
9
+ end
10
+
11
+ def validate!
12
+ interface_methods.each do |method_signature|
13
+ unless class_has_method?(klass, method_signature.name)
14
+ raise Bossy::Errors::MethodMissing, "Please define #{klass}##{method_signature.name} with the signature:\n\n#{method_signature}\n\n"
15
+ end
16
+ end
17
+
18
+ return true
19
+ end
20
+
21
+ def add_required_methods(m)
22
+ @interface_methods += m
23
+ end
24
+
25
+ def to_s
26
+ bullet = "\u279E".encode
27
+ s = "Interface for #{@klass}\n"
28
+ s += interface_methods.map{|m| "#{bullet} #{m}" }.join("\n")
29
+ return s
30
+ end
31
+
32
+ def print
33
+ puts to_s
34
+ end
35
+
36
+ def class_has_method?(klass, method_name)
37
+ klass.instance_methods(true).include?(method_name)
38
+ end
39
+ private :class_has_method?
40
+
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # This class encapsulates the definition of a method signature.
2
+ # That includes the method name, return type, parameters and parameter types.
3
+ # Basically it captures: `String my_method(Integer arg1, Float arg2)`.
4
+ # You can instantiate this class by calling:
5
+ # `Bossy::MethodSignature.new(String: :my_method, Integer: :arg1, Float: :arg2)`
6
+ #
7
+ module Bossy
8
+ class MethodSignature
9
+ attr_reader :name
10
+
11
+ def initialize(method_type, method_name, args)
12
+ @type = method_type
13
+ @name = method_name
14
+ @name = @name.to_s if RUBY_VERSION.to_f < 1.9
15
+ @args = args
16
+ end
17
+
18
+ def to_s
19
+ "#{@type} #{@name}(#{args_to_s(@args)})"
20
+ end
21
+
22
+ def args_to_s(args)
23
+ args.map{|nt| "#{nt.first} #{nt.last}"}.join(", ")
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bossy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stasio
@@ -50,6 +50,10 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - lib/bossy/class_methods.rb
54
+ - lib/bossy/errors/method_missing.rb
55
+ - lib/bossy/interface.rb
56
+ - lib/bossy/method_signature.rb
53
57
  - lib/bossy.rb
54
58
  homepage: http://nowhere.yet
55
59
  licenses: