Skip to content

Commit

Permalink
WiP - use set_build (not working on array) - #23
Browse files Browse the repository at this point in the history
  • Loading branch information
FCO committed Aug 24, 2018
1 parent 9b63ba0 commit 5c74139
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
1 change: 0 additions & 1 deletion lib/MetamodelX/Red/Model.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ method attr-to-column(|) is rw {
}

method compose(Mu \type) {
type.^prepare-relationships;
if $.rs-class === Any {
my $rs-class-name = $.rs-class-name(type);
if try ::($rs-class-name) !~~ Nil {
Expand Down
15 changes: 2 additions & 13 deletions lib/MetamodelX/Red/Relationship.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ method relationships(|) {
%!relationships
}

method prepare-relationships(::Type Mu \type) {
type.^add_method: 'new', my method new(Type: *%data) {
my \instance = callsame;
for self.^relationships.keys -> $rel {
$rel.build-relationship: instance
}
instance
}
}

multi method add-relationship(Mu:U $self, Attribute $attr, &reference) {
$attr does Red::Attr::Relationship[&reference];
self.add-relationship: $self, $attr
Expand All @@ -35,9 +25,8 @@ multi method add-relationship(Mu:U $self, Red::Attr::Relationship $attr) {
$attr.get_value: self
} if $attr.has_accessor;
$self.^add_multi_method: $name, my method (Mu:U:) {
# TODO: use fake seq
# Red::FakeSeq.new: :of($self.WHAT), :ast($attr.relationship-ast)
my $ast = $attr.relationship-ast;
Red::FakeSeq.new: :of($self.WHAT), :$ast
$attr.type.^rs.new: :of($self.WHAT), :$ast
}
$attr.prepare-relationship;
}
30 changes: 14 additions & 16 deletions lib/Red/Attr/Relationship.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ use Red::AST::Infixes;
unit role Red::Attr::Relationship[&rel1, &rel2?];
has Mu:U $!type;

method build-relationship(\instance) {
method prepare-relationship {
my \type = self.type;
self.set_value: instance, Proxy.new:
FETCH => method () {
do if type ~~ Positional {
my $rel = rel1 type.of;
my \value = $rel.references.().attr.get_value: instance;
type.of.^rs.where: Red::AST::Eq.new: $rel, value, :bind-right
} else {
my $rel = rel1 instance.WHAT;
my \ref = $rel.references.();
my \value = $rel.attr.get_value: instance;
type.^rs.where(Red::AST::Eq.new: ref, value, :bind-right).head
}
},
STORE => method ($value) {
die "Couldnt set value"
if type ~~ Positional {
self.set_build: -> \instance, | {
my $rel = rel1 type.of;
my \value = $rel.references.().attr.get_value: instance;
type.of.^rs.where: Red::AST::Eq.new: $rel, value, :bind-right
}
} else {
self.set_build: -> \instance, | {
my $rel = rel1 instance.WHAT;
my \ref = $rel.references.();
my \value = $rel.attr.get_value: instance;
type.^rs.where(Red::AST::Eq.new: ref, value, :bind-right).head
}
}
}

method relationship-ast {
Expand Down
9 changes: 2 additions & 7 deletions lib/Red/ResultSeq.pm6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use Red::AST;
use Red::FakeSeq;
unit role Red::ResultSeq;
unit role Red::ResultSeq does Positional;

has Red::AST $.filter;

Expand All @@ -17,12 +17,7 @@ method transform-item(*%data) {
}

method iterator {
my $resultseq = self;
class :: does Iterator {
method pull-one {
$resultseq.transform-item
}
}
[self.of].iterator
}

method grep(&filter) { self.where: filter self.of }

0 comments on commit 5c74139

Please sign in to comment.