Class: Alf::Viewpoint::Metadata
- Inherits:
-
Object
- Object
- Alf::Viewpoint::Metadata
- Defined in:
- lib/alf/viewpoint/metadata.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#expectations ⇒ Object
readonly
Returns the value of attribute expectations.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #add_members(members) ⇒ Object
- #all_members ⇒ Object
- #depends(pairs) ⇒ Object
- #dup ⇒ Object
- #expand ⇒ Object
- #expects(viewpoints) ⇒ Object
-
#initialize(expectations = [], dependencies = {}, members = []) {|_self| ... } ⇒ Metadata
constructor
A new instance of Metadata.
- #to_module(context = {}, &bl) ⇒ Object
Constructor Details
#initialize(expectations = [], dependencies = {}, members = []) {|_self| ... } ⇒ Metadata
Returns a new instance of Metadata.
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
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
11 12 13 |
# File 'lib/alf/viewpoint/metadata.rb', line 11 def dependencies @dependencies end |
#expectations ⇒ Object (readonly)
Returns the value of attribute expectations.
11 12 13 |
# File 'lib/alf/viewpoint/metadata.rb', line 11 def expectations @expectations end |
#members ⇒ Object (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_members ⇒ Object
33 34 35 |
# File 'lib/alf/viewpoint/metadata.rb', line 33 def all_members .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 |
#dup ⇒ Object
50 51 52 |
# File 'lib/alf/viewpoint/metadata.rb', line 50 def dup Metadata.new(expectations.dup, dependencies.dup, members.dup) end |
#expand ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/alf/viewpoint/metadata.rb', line 37 def Metadata.new do |m| expectations.map{|e| e.. }.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) = Module.new{ include Alf::Viewpoint define_method(:contextual_params) do context end .expectations.each do |exp| include(exp) end .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 |