Module: Interface::DSL
- Included in:
- PortGroup
- Defined in:
- lib/interface/dsl.rb
Constant Summary
collapse
- OrphanPort =
Class.new(StandardError)
- ImmutableInterface =
Class.new(StandardError)
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/interface/dsl.rb', line 28
def method_missing(meth, *args, &block)
super unless respond_to?(:interfaces) || respond_to?(:points)
if interfaces.respond_to?(meth)
interfaces.send(meth)
elsif points.respond_to?(meth)
points.send(meth)
else
super
end
end
|
Instance Method Details
#defpoint(name, &block) ⇒ Object
22
23
24
25
26
|
# File 'lib/interface/dsl.rb', line 22
def defpoint(name, &block)
check_top_level_enpoint_policy
points.merge!(name => define_entity(name, &block))
end
|
#doc ⇒ Object
48
49
50
51
52
53
|
# File 'lib/interface/dsl.rb', line 48
def doc
_name = self.respond_to?(:name) ? self.name : self.class.name
puts _name
doc_all_endpoints
interfaces.each_pair { |_, i| i.doc }
end
|
#extend_api(as:, with_class:) ⇒ Object
extend_api(as: ‘northbound.operations.truck_load’, with_class: TruckLoadAPI)
41
42
43
44
45
46
|
# File 'lib/interface/dsl.rb', line 41
def extend_api(as: , with_class: )
_merge_point = respond_to?(:points) ? points : self
_merge_point.merge!(as => with_class)
end
|
#interface(name, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/interface/dsl.rb', line 12
def interface(name, &block)
if interfaces.key?(name)
fail(ImmutableInterface.new("Interface can't be redefined or reopened! Use .extend_api method"))
end
interfaces.merge!(name => ::Interface::PortGroup.new(name, self).tap do |group|
group.instance_eval(&block)
end)
end
|
#interfaces ⇒ Object
55
56
57
|
# File 'lib/interface/dsl.rb', line 55
def interfaces
@interfaces ||= Hashie::Mash.new
end
|
#points ⇒ Object
59
60
61
|
# File 'lib/interface/dsl.rb', line 59
def points
@points ||= Hashie::Mash.new
end
|