Class: Alf::Viewpoint::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/alf-viewpoint/alf/viewpoint/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expectations = [], dependencies = {}, members = []) {|_self| ... } ⇒ Metadata

Returns a new instance of Metadata.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
10
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 5

def initialize(expectations = [], dependencies = {}, members = [])
  @expectations = expectations
  @dependencies = dependencies
  @members      = members
  yield(self) if block_given?
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



11
12
13
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 11

def dependencies
  @dependencies
end

#expectationsObject (readonly)

Returns the value of attribute expectations.



11
12
13
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 11

def expectations
  @expectations
end

#membersObject (readonly)

Returns the value of attribute members.



11
12
13
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 11

def members
  @members
end

Instance Method Details

#add_members(members) ⇒ Object



25
26
27
28
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 25

def add_members(members)
  @members |= members
  self
end

#all_membersObject



30
31
32
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 30

def all_members
  expand.members
end

#depends(pairs) ⇒ Object



18
19
20
21
22
23
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 18

def depends(pairs)
  @dependencies.merge!(pairs) do |k,v1,v2|
    v1 == v2 ? v1 : raise("Composition conflict on `#{k}`: #{v1.inspect} vs. #{v2.inspect}")
  end
  self
end

#dupObject



47
48
49
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 47

def dup
  Metadata.new(expectations.dup, dependencies.dup, members.dup)
end

#expandObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 34

def expand
  Metadata.new do |m|
    expectations.map{|e| e..expand }.each do |m2|
      m.expects(m2.expectations)
      m.depends(m2.dependencies)
      m.add_members(m2.members)
    end
    m.expects(expectations)
    m.depends(dependencies)
    m.add_members(members)
  end
end

#expects(viewpoints) ⇒ Object



13
14
15
16
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 13

def expects(viewpoints)
  @expectations |= viewpoints
  self
end

#to_module(context = {}, &bl) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/alf-viewpoint/alf/viewpoint/metadata.rb', line 51

def to_module(context = {}, &bl)
  expanded = expand
  Module.new{
    include Alf::Viewpoint
    define_method(:contextual_params) do
      context
    end
    expanded.expectations.each do |exp|
      include(exp)
    end
    expanded.dependencies.each_pair do |as, vps|
      provider = Metadata.new(vps).to_module(context)
      define_method(as) do
        Lang::Lispy.new([provider], connection)
      end
    end
    instance_exec(&bl) if bl
  }
end