Class: Alf::Viewpoint::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/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/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/metadata.rb', line 11

def dependencies
  @dependencies
end

#expectationsObject (readonly)

Returns the value of attribute expectations


11
12
13
# File 'lib/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/metadata.rb', line 11

def members
  @members
end

Instance Method Details

#add_members(members) ⇒ Object


28
29
30
31
# File 'lib/alf/viewpoint/metadata.rb', line 28

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

#all_membersObject


33
34
35
# File 'lib/alf/viewpoint/metadata.rb', line 33

def all_members
  expand.members
end

#depends(pairs) ⇒ Object


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

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

#dupObject


50
51
52
# File 'lib/alf/viewpoint/metadata.rb', line 50

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

#expandObject


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/alf/viewpoint/metadata.rb', line 37

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/metadata.rb', line 13

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

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


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

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::Parser::Lispy.new([provider], connection)
      end
    end
    instance_exec(&bl) if bl
  }
end