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 +4 -4
- data/lib/bossy/class_methods.rb +14 -0
- data/lib/bossy/errors/method_missing.rb +6 -0
- data/lib/bossy/interface.rb +42 -0
- data/lib/bossy/method_signature.rb +26 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c47b19da9df1ee76c5afb78b067dd8887f651a1d
|
|
4
|
+
data.tar.gz: 6c90c4c8942e7fb4ec4638516634008a034a626b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,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
|
+
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:
|