Class: Accord::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/accord/specification.rb

Direct Known Subclasses

Declarations::Declaration, InterfaceClass

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Specification

Returns a new instance of Specification.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/accord/specification.rb', line 6

def initialize(*args)
  if args.size == 2 || args.first.is_a?(String) || args.first.is_a?(Symbol)
    @name = args.first.to_s
    bases = (args.size == 2 ? (args[1] || []) : [])
  else
    @name = '?'
    bases = args.first || []
  end
  @dependents = Set.new
  @ro = Accord::RO.new(self) { |spec| spec.bases }
  self.bases = bases
end

Instance Method Details

#ancestorsObject



54
55
56
# File 'lib/accord/specification.rb', line 54

def ancestors
  @ro.resolve
end

#basesObject



19
20
21
# File 'lib/accord/specification.rb', line 19

def bases
  (@bases || []).dup
end

#bases=(new_bases) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/accord/specification.rb', line 23

def bases= new_bases
  new_bases = new_bases.uniq
  new_bases.each do |base|
    raise TypeError,
      'cannot use something other than Specification as a base' \
      unless base.is_a?(Specification)
  end

  bases.each { |base| base.unsubscribe(self) }
  new_bases.each { |base| base.subscribe(self) }

  @bases = new_bases

  changed(self)
end

#each_interfaceObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/accord/specification.rb', line 39

def each_interface
  seen = Set.new
  @bases.each do |base|
    base.each_interface do |interface|
      next if seen.include?(interface)
      seen << interface
      yield(interface)
    end
  end
end

#extends?(other) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/accord/specification.rb', line 58

def extends?(other)
  ancestors.include?(other)
end

#inspectObject



62
63
64
# File 'lib/accord/specification.rb', line 62

def inspect
  "<Specification #{@name.inspect}>"
end

#interfacesObject



50
51
52
# File 'lib/accord/specification.rb', line 50

def interfaces
  enum_for(:each_interface).to_a
end