circuits 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTQ4YTRjMjcwYmU5OGRiY2MzMzhkNzkxZDNlNDI5MGQ5NWU5YzYwNg==
4
+ ZDQ3YmZhMTQxMjJmODRhZDQ1MDA0MWU2ZTc3NTIxNTljY2E3MzA2OQ==
5
5
  data.tar.gz: !binary |-
6
- YjgxYmQ4M2E2MzQ1OTI3ZGI2NDBjZjBlZTc3ZDU0MmViNTU3ZjQxYQ==
6
+ NzJhYTU4NjRhNjhmMWFmOWJjZjM5MTg5YzhkZmFhYzY4ODYyZjdhNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTY0MzBjODYzMzJjNTRkZmJlMjgxYmY1ZGUyNTdlMzM3NGQ1YWQ5ZjU1YjZk
10
- ODQ4MGQwZmE3NjI4MjY5MGZkY2RhYTQxOWUyYzJiOWU5NzJjOWZhMDg4YmU3
11
- MjhjOWQ1NzdjNzFlOGM1ZmJjNzhkODg2M2MwMzQ1NTA4MGViZmI=
9
+ NDkxODk0MmRlZTk1MjdlMGRmODAzMWExZDNjMDllNWVjYWVkMTM3NTcyZjFh
10
+ ZWQwYmI2MzQ5ZjZkMTZjMGZkMWE4ZTdlM2Y5NjJhZmI2N2I1ZWZhMWZmYWZk
11
+ MTY4M2E2NDE3YTYxNmRjZjQ0NzVjZWVmM2NkMWMxYWY1NTMxNjk=
12
12
  data.tar.gz: !binary |-
13
- MWVkNTg2Y2E5NDQ1ZDViMjMyMDBlZTQzYmNjZGMzNjRiZTc1YzVjZjc5NDkw
14
- MWYwZmE5ZTlkMmYwYzZkNGEwNTQ2YTcxMmY1ZDRmM2MyZWEwYzYxM2QyNTBk
15
- ZjNkNmRkZDc4OTQ3ZDQwMDM2NDYzOGIzZjk2NmIxMDc0NTQ5MjQ=
13
+ N2VmZWMyZWQ5NzViMjUxNGNlNThiY2I0MzlhYzc5NjE0ZGUyOThkYjlhMmY1
14
+ YzExOWQxZTlmNDg5MDZkYjc0YjMxYzcwNDRlNWQ5ZjA3MzZlNzg2ZjQyNzJl
15
+ NTI4OGViNDMzNzA2OTA3NzcxZDNjMTM1MzFjM2Q0Njg0YzJjNzY=
@@ -21,6 +21,7 @@ module Circuits
21
21
  @port_mappings = create_port_mappings opts
22
22
  @sub_components = opts[:sub_components] || []
23
23
  @ticks = opts[:ticks] || 0
24
+ declare_ports_as_methods
24
25
  end
25
26
 
26
27
  # the inputs of this component
@@ -29,15 +30,6 @@ module Circuits
29
30
  # the outputs of this component
30
31
  attr_reader :outputs
31
32
 
32
- # For easy access to the ports
33
- # @param [Symbol] method_name The name of the method
34
- # @return [Input, Outpus] The corresponding port
35
- def method_missing(method_name, *_, &__)
36
- res = self[method_name]
37
- super if res.nil?
38
- res
39
- end
40
-
41
33
  # Computes the outputs based on the inputs and previous state
42
34
  def tick
43
35
  @ticks.times.each do
@@ -51,13 +43,6 @@ module Circuits
51
43
  outputs.each(&:tock)
52
44
  end
53
45
 
54
- # So we can advertise what ports are available from {#method_missing}
55
- # @param [Symbol] method_name The name of the method
56
- # @return [Boolean] Wether or a method call will be responded to
57
- def respond_to_missing?(method_name, _)
58
- !self[method_name].nil? || super
59
- end
60
-
61
46
  # Gets the teminal assigned to the port
62
47
  # @param port [Symbol] The symbol that represents the terminal
63
48
  # @return [Input, Output] The terminal
@@ -94,6 +79,16 @@ module Circuits
94
79
  res
95
80
  end
96
81
 
82
+ def declare_ports_as_methods
83
+ @port_mappings.each do |method, _|
84
+ (class << self; self; end).class_eval do
85
+ define_method method do
86
+ self[method]
87
+ end
88
+ end
89
+ end
90
+ end
91
+
97
92
  def input_mappings(input_names)
98
93
  return default_input_mappings unless input_names.class == Array
99
94
  input_names.map.each_with_index do |input_name, num|
@@ -1,5 +1,5 @@
1
1
  # Circuits allows you to express logical circuits in code
2
2
  module Circuits
3
3
  # The version of the Circuits gem
4
- VERSION = '0.11.0'
4
+ VERSION = '0.11.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Muru Paenga