Class: Accord::InterfaceBody
- Inherits:
-
Object
- Object
- Accord::InterfaceBody
- Defined in:
- lib/accord/interface_body.rb
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
Class Method Summary collapse
Instance Method Summary collapse
- #extends(*new_bases) ⇒ Object
-
#initialize(interface, bases, members, invariants) ⇒ InterfaceBody
constructor
A new instance of InterfaceBody.
- #invariant(invariant_name, &block) ⇒ Object
- #responds_to(name, options = {}, &block) ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(interface, bases, members, invariants) ⇒ InterfaceBody
Returns a new instance of InterfaceBody.
7 8 9 10 11 12 |
# File 'lib/accord/interface_body.rb', line 7 def initialize(interface, bases, members, invariants) @interface = interface @bases = bases @members = members @invariants = invariants end |
Instance Attribute Details
#interface ⇒ Object (readonly)
Returns the value of attribute interface.
5 6 7 |
# File 'lib/accord/interface_body.rb', line 5 def interface @interface end |
Class Method Details
.make_method(interface, name, options, block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/accord/interface_body.rb', line 47 def self.make_method(interface, name, , block) arguments = SignatureInfo.new if args = [:params] raise ArgumentError, "no block is expected when using option `:params`." if block args = [args] unless args.is_a?(Array) args.each do |arg| if arg.is_a?(Symbol) if arg.to_s.start_with?('&') arguments.block(arg.to_s.gsub(/^&/, '').to_sym) elsif arg.to_s.start_with?('*') arguments.splat(arg.to_s.gsub(/^\*/, '').to_sym) else arguments.param(arg) end else arguments.param(arg) end end elsif block arguments.instance_exec(&block) end InterfaceMethod.new(interface, name, arguments) end |
.run(interface, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/accord/interface_body.rb', line 33 def self.run(interface, &block) bases = [] members = interface.members invariants = interface.invariants body = new(interface, bases, members, invariants) body.instance_exec(&block) if block bases.unshift(Interface) if bases.empty? interface.bases = bases interface end |
Instance Method Details
#extends(*new_bases) ⇒ Object
14 15 16 17 18 |
# File 'lib/accord/interface_body.rb', line 14 def extends(*new_bases) new_bases.each do |base| @bases.unshift(base) unless @bases.include?(base) end end |
#invariant(invariant_name, &block) ⇒ Object
25 26 27 |
# File 'lib/accord/interface_body.rb', line 25 def invariant(invariant_name, &block) @invariants.add(invariant_name, &block) end |
#responds_to(name, options = {}, &block) ⇒ Object
20 21 22 23 |
# File 'lib/accord/interface_body.rb', line 20 def responds_to(name, ={}, &block) method = self.class.make_method(interface, name, , block) @members.add(name, method) end |
#tags ⇒ Object
29 30 31 |
# File 'lib/accord/interface_body.rb', line 29 def interface. end |