patriarch 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/patriarch.rb +2 -0
- data/lib/patriarch/authorization_service.rb +14 -45
- data/lib/patriarch/behaviours.rb +48 -61
- data/lib/patriarch/dao_services/bipartite_relationship_builder_service.rb +8 -16
- data/lib/patriarch/dao_services/tripartite_relationship_builder_service.rb +11 -13
- data/lib/patriarch/redis_instruction.rb +8 -0
- data/lib/patriarch/tool_services/redis_cleaner_service.rb +76 -73
- data/lib/patriarch/tool_services/redis_extractor_service.rb +1 -0
- data/lib/patriarch/transaction.rb +1 -1
- data/lib/patriarch/transaction_step.rb +11 -8
- data/lib/patriarch/version.rb +1 -1
- data/spec/lib/patriarch/dao_services/bipartite_relationship_builder_spec.rb +2 -2
- data/spec/lib/patriarch/dao_services/tripartite_relationship_builder_spec.rb +2 -2
- metadata +3 -2
data/lib/patriarch.rb
CHANGED
@@ -13,6 +13,8 @@ module Patriarch
|
|
13
13
|
autoload :InstallGenerator, 'generators/patriarch/install_generator'
|
14
14
|
end
|
15
15
|
|
16
|
+
autoload :RedisInstruction, 'patriarch/redis_instruction'
|
17
|
+
|
16
18
|
autoload :Service, 'patriarch/service'
|
17
19
|
autoload :Transaction, 'patriarch/transaction'
|
18
20
|
autoload :TransactionStep, 'patriarch/transaction_step'
|
@@ -12,58 +12,27 @@ module Patriarch
|
|
12
12
|
# Since type verification is an eternal we implement grant in the mother class and let daughter classes
|
13
13
|
# call it with super and benefit from verify_types or bypass it completely and override the function
|
14
14
|
def grant?(transac)
|
15
|
-
|
16
|
-
true
|
17
|
-
else
|
18
|
-
raise Patriarch::ForbiddenBehaviourException, "that behaviour is not authorized"
|
19
|
-
end
|
15
|
+
check_types(transac) || raise(Patriarch::ForbiddenBehaviourException, "that behaviour is not authorized")
|
20
16
|
end
|
21
17
|
|
22
|
-
# When declaring behaviours in model thanks to add_behaviour helper we enforce that ONLY the
|
18
|
+
# When declaring behaviours in model thanks to add_behaviour helper we enforce that ONLY the declared behaviours
|
23
19
|
# are authorized. We hence verify that when a behaviour is called.
|
24
20
|
# For example User could be able to like Items and thus be blessed with #like as an instance method.
|
25
|
-
# But then we can
|
21
|
+
# But then we can call like upon from any user instance to like any object, this method prevents it.
|
26
22
|
# @transac [Patriarch::Transaction] the transaction to be authorized (or not)
|
27
23
|
def check_types(transac)
|
28
|
-
|
29
|
-
actor_model_sym = actor_model.name.underscore.to_sym
|
30
|
-
|
31
|
-
target_model = transac.target.class
|
32
|
-
target_model_sym = target_model.name.underscore.to_sym
|
33
|
-
|
34
|
-
medium_model = transac.medium.class
|
35
|
-
medium_model_sym = medium_model.name.underscore.to_sym
|
36
|
-
|
24
|
+
protagonists_models = transac.protagonists_models
|
37
25
|
behaviour = transac.relation_type.to_s.sub(/undo_/,'').underscore.to_sym
|
38
26
|
auths = []
|
39
27
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
auths <<
|
44
|
-
|
45
|
-
# Verification for target
|
46
|
-
auths << target_model.patriarch_behaviours[behaviour][:by].map{ |b_sym| b_sym.to_s.underscore.to_sym }.include?(actor_model_sym)
|
47
|
-
auths << target_model.patriarch_behaviours[behaviour][:via].map{ |b_sym| b_sym.to_s.underscore.to_sym }.include?(medium_model_sym)
|
48
|
-
|
49
|
-
# Verification for medium
|
50
|
-
# Pay attention here since add_behaviour syntax is different when being a medium
|
51
|
-
auths << medium_model.patriarch_behaviours[behaviour][:medium_between].map do |dual_sym_tab|
|
52
|
-
dual_sym_tab.map{ |b_sym| b_sym.to_s.underscore.to_sym }
|
53
|
-
end.include?(
|
54
|
-
[actor_model_sym, target_model_sym]
|
55
|
-
)
|
56
|
-
else
|
57
|
-
auths << actor_model.patriarch_behaviours[behaviour][:on].map{ |b_sym| b_sym.to_s.underscore.to_sym }.include?(target_model_sym)
|
58
|
-
auths << target_model.patriarch_behaviours[behaviour][:by].map{ |b_sym| b_sym.to_s.underscore.to_sym }.include?(actor_model_sym)
|
28
|
+
# See register behaviour to see how it is implemented.
|
29
|
+
# TODO Couplage trop grand ici.
|
30
|
+
protagonists_models.each do |protagonist_model|
|
31
|
+
auths << protagonist_model.patriarch_behaviours[behaviour].include?(protagonists_models)
|
59
32
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
33
|
+
|
34
|
+
!auths.include?(false)
|
35
|
+
end # def check_types
|
36
|
+
|
37
|
+
end # class AuthorizationService
|
38
|
+
end # module Patriarch
|
data/lib/patriarch/behaviours.rb
CHANGED
@@ -347,7 +347,7 @@ module Patriarch
|
|
347
347
|
end
|
348
348
|
|
349
349
|
if options[:on]
|
350
|
-
module_to_complete.
|
350
|
+
module_to_complete.class_eval do
|
351
351
|
# add behaviour_alias
|
352
352
|
if options[:as]
|
353
353
|
alias_method behaviour_alias, behaviour
|
@@ -365,15 +365,15 @@ module Patriarch
|
|
365
365
|
# @param [String] behaviour
|
366
366
|
# Add basic behaviours calls to models in bipartite situations
|
367
367
|
def add_functionality_for_bipartite(anon_module,behaviour)
|
368
|
-
anon_module.
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
368
|
+
anon_module.class_eval do
|
369
|
+
|
370
|
+
# use define_method to get otherwise out of scope variables
|
371
|
+
# usage of self.send(:define_method,:included) would fail as it would declare included
|
372
|
+
# as a method available to class including this module not as an override of the included
|
373
|
+
# hook
|
374
|
+
(class << self; self; end).send(:define_method,:included) do |klass|
|
375
|
+
klass.extend ActiveModel::Callbacks
|
376
|
+
klass.send(:define_model_callbacks, behaviour, Patriarch.undo(behaviour))
|
377
377
|
end
|
378
378
|
|
379
379
|
# behave
|
@@ -390,22 +390,22 @@ module Patriarch
|
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
-
end #
|
393
|
+
end # class_eval
|
394
394
|
end
|
395
395
|
|
396
396
|
# @param [Module] anon_module
|
397
397
|
# @param [String] behaviour
|
398
398
|
# Add basic behaviours calls to models in tripartite situations
|
399
399
|
def add_functionality_for_tripartite(anon_module,behaviour)
|
400
|
-
anon_module.
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
400
|
+
anon_module.class_eval do
|
401
|
+
|
402
|
+
# use define_method to get otherwise out of scope variables
|
403
|
+
# usage of self.send(:define_method,:included) would fail as it would declare included
|
404
|
+
# as a method available to class including this module not as an override of the included
|
405
|
+
# hook
|
406
|
+
(class << self; self; end).send(:define_method,:included) do |klass|
|
407
|
+
klass.extend ActiveModel::Callbacks
|
408
|
+
klass.send(:define_model_callbacks, behaviour, Patriarch.undo(behaviour))
|
409
409
|
end
|
410
410
|
|
411
411
|
# behave
|
@@ -415,7 +415,6 @@ module Patriarch
|
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
418
|
-
|
419
418
|
# undo_behave
|
420
419
|
define_method(Patriarch.undo(behaviour)) do |via_entity,entity,options={}|
|
421
420
|
run_callbacks Patriarch.undo(behaviour).to_sym do
|
@@ -423,7 +422,7 @@ module Patriarch
|
|
423
422
|
end
|
424
423
|
end
|
425
424
|
|
426
|
-
end #
|
425
|
+
end # class_eval
|
427
426
|
end
|
428
427
|
|
429
428
|
# @param [String] behaviour
|
@@ -434,19 +433,14 @@ module Patriarch
|
|
434
433
|
behaviour = behaviour.underscore.to_sym
|
435
434
|
|
436
435
|
self.patriarch_behaviours ||= { }
|
437
|
-
|
438
|
-
self.patriarch_behaviours[behaviour] ||= { }
|
439
|
-
self.patriarch_behaviours[behaviour][:on] ||= []
|
440
|
-
self.patriarch_behaviours[behaviour][:by] ||= []
|
436
|
+
self.patriarch_behaviours[behaviour] ||= []
|
441
437
|
|
442
|
-
|
443
|
-
self.patriarch_behaviours[behaviour]
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
self.patriarch_behaviours[behaviour]
|
448
|
-
self.patriarch_behaviours[behaviour][:by].uniq!
|
449
|
-
self.patriarch_behaviours[behaviour][:by].flatten!
|
438
|
+
Array(options[:on]).each do |target_class_sym|
|
439
|
+
self.patriarch_behaviours[behaviour] << [self,target_class_sym.to_s.classify.constantize]
|
440
|
+
end
|
441
|
+
|
442
|
+
Array(options[:by]).each do |actor_class_sym|
|
443
|
+
self.patriarch_behaviours[behaviour] << [actor_class_sym.to_s.classify.constantize,self]
|
450
444
|
end
|
451
445
|
end
|
452
446
|
|
@@ -458,35 +452,28 @@ module Patriarch
|
|
458
452
|
behaviour = behaviour.underscore.to_sym
|
459
453
|
|
460
454
|
self.patriarch_behaviours ||= { }
|
461
|
-
self.patriarch_behaviours[behaviour] ||=
|
455
|
+
self.patriarch_behaviours[behaviour] ||= []
|
462
456
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
#self.patriarch_behaviours[behaviour.underscore.to_sym] ||= { :medium_between => [] }
|
470
|
-
self.patriarch_behaviours[behaviour][:medium_between] ||= []
|
471
|
-
end
|
457
|
+
Array(options[:via]).each do |medium_class_sym|
|
458
|
+
Array(options[:on]).each do |target_class_sym|
|
459
|
+
target_class = target_class_sym.to_s.classify.constantize
|
460
|
+
medium_class = medium_class_sym.to_s.classify.constantize
|
461
|
+
self.patriarch_behaviours[behaviour] << [self, target_class, medium_class]
|
462
|
+
end
|
472
463
|
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
self.patriarch_behaviours[behaviour][
|
477
|
-
self.patriarch_behaviours[behaviour][:on].flatten!
|
478
|
-
elsif options[:by]
|
479
|
-
self.patriarch_behaviours[behaviour][:by] << options[:by]
|
480
|
-
self.patriarch_behaviours[behaviour][:by].uniq!
|
481
|
-
self.patriarch_behaviours[behaviour][:by].flatten!
|
464
|
+
Array(options[:by]).each do |actor_class_sym|
|
465
|
+
actor_class = actor_class_sym.to_s.classify.constantize
|
466
|
+
medium_class = medium_class_sym.to_s.classify.constantize
|
467
|
+
self.patriarch_behaviours[behaviour] << [actor_class, self, medium_class]
|
482
468
|
end
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
469
|
+
end
|
470
|
+
|
471
|
+
# FIXME should support enumerations of medium betweens like this
|
472
|
+
# [[actor1,target1],[actor2,target2]]
|
473
|
+
if options[:medium_between]
|
474
|
+
actor_class = options[:medium_between].first.to_s.classify.constantize
|
475
|
+
target_class = options[:medium_between].last.to_s.classify.constantize
|
476
|
+
self.patriarch_behaviours[behaviour] << [actor_class, target_class, self]
|
490
477
|
end
|
491
478
|
end
|
492
479
|
|
@@ -558,7 +545,7 @@ module Patriarch
|
|
558
545
|
# register the behaviour we just added
|
559
546
|
register_bipartite_behaviour(behaviour,options)
|
560
547
|
end
|
561
|
-
end
|
548
|
+
end # module Class Methods
|
562
549
|
|
563
550
|
end # Behaviours
|
564
551
|
end # Patriarch
|
@@ -16,13 +16,9 @@ class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::S
|
|
16
16
|
actor_dao = dao_tab[:actor]
|
17
17
|
target_dao = dao_tab[:target]
|
18
18
|
|
19
|
-
l =
|
20
|
-
ll =
|
19
|
+
l = build_struct_for_create(actor_dao,transaction_item.target_id,t)
|
20
|
+
ll = build_struct_for_create(target_dao,transaction_item.actor_id,t)
|
21
21
|
|
22
|
-
p "#{l.inspect} is creating on key #{actor_dao.key} : #{transaction_item.target_type} #{transaction_item.target_id}"
|
23
|
-
p "#{ll.inspect} is creating on key #{target_dao.key} : #{transaction_item.actor_type} #{transaction_item.actor_id}"
|
24
|
-
|
25
|
-
# care about that, should be encapsulated into a beautiful add_to_queue method
|
26
22
|
transaction_item.add_to_queue l
|
27
23
|
transaction_item.add_to_queue ll
|
28
24
|
end
|
@@ -36,10 +32,8 @@ class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::S
|
|
36
32
|
actor_dao = dao_tab[:actor]
|
37
33
|
target_dao = dao_tab[:target]
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
l = OpenStruct.new(:method_sym => :delete ,:dao => actor_dao, :args => [transaction_item.target_id])
|
42
|
-
ll = OpenStruct.new(:method_sym => :delete ,:dao => target_dao, :args => [transaction_item.actor_id])
|
35
|
+
l = Patriarch::RedisInstruction.new(actor_dao,:delete,[transaction_item.target_id])
|
36
|
+
ll = Patriarch::RedisInstruction.new(target_dao,:delete ,[transaction_item.actor_id])
|
43
37
|
|
44
38
|
transaction_item.add_to_queue l
|
45
39
|
transaction_item.add_to_queue ll
|
@@ -49,14 +43,12 @@ class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::S
|
|
49
43
|
# @param [Redis::Objects] dao
|
50
44
|
# @param [Array] ids
|
51
45
|
# @param [Time] time
|
52
|
-
# Returns
|
53
|
-
def
|
46
|
+
# Returns Patriarch::RedisInstruction (structs) objects that store parameters to execute a redis operation
|
47
|
+
def build_struct_for_create(dao,id,time)
|
54
48
|
if dao.is_a? Redis::SortedSet
|
55
|
-
return
|
56
|
-
# return lambda { dao.add ids, time }
|
49
|
+
return Patriarch::RedisInstruction.new(dao,:add,[id,time])
|
57
50
|
else
|
58
|
-
return
|
59
|
-
# return lambda { dao.add ids }
|
51
|
+
return Patriarch::RedisInstruction.new(dao,:add,[id])
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
@@ -20,9 +20,9 @@ class Patriarch::DAOServices::TripartiteRelationshipBuilderService < Patriarch::
|
|
20
20
|
|
21
21
|
protagonist_ids = [transaction_item.actor_id,transaction_item.target_id,transaction_item.medium_id]
|
22
22
|
|
23
|
-
l =
|
24
|
-
ll =
|
25
|
-
lll =
|
23
|
+
l = build_struct_for_create(actor_dao,protagonist_ids,t)
|
24
|
+
ll = build_struct_for_create(target_dao,protagonist_ids,t)
|
25
|
+
lll = build_struct_for_create(medium_dao,protagonist_ids,t)
|
26
26
|
|
27
27
|
# care about that, should be encapsulated into a beautiful add_to_queue method
|
28
28
|
transaction_item.add_to_queue l
|
@@ -46,9 +46,9 @@ class Patriarch::DAOServices::TripartiteRelationshipBuilderService < Patriarch::
|
|
46
46
|
#ll = lambda { target_dao.delete protagonist_ids }
|
47
47
|
#lll = lambda { medium_dao.delete protagonist_ids }
|
48
48
|
|
49
|
-
l =
|
50
|
-
ll =
|
51
|
-
lll =
|
49
|
+
l = Patriarch::RedisInstruction.new(actor_dao ,:delete,[protagonist_ids])
|
50
|
+
ll = Patriarch::RedisInstruction.new(target_dao,:delete,[protagonist_ids])
|
51
|
+
lll = Patriarch::RedisInstruction.new(medium_dao,:delete,[protagonist_ids])
|
52
52
|
|
53
53
|
transaction_item.add_to_queue l
|
54
54
|
transaction_item.add_to_queue ll
|
@@ -59,14 +59,12 @@ class Patriarch::DAOServices::TripartiteRelationshipBuilderService < Patriarch::
|
|
59
59
|
# @param [Redis::Objects] dao
|
60
60
|
# @param [Array] ids
|
61
61
|
# @param [Time] time
|
62
|
-
# Returns
|
63
|
-
def
|
62
|
+
# Returns Patriarch::RedisInstruction (structs) objects that store parameters to execute a redis operation
|
63
|
+
def build_struct_for_create(dao,ids,time)
|
64
64
|
if dao.is_a? Redis::SortedSet
|
65
|
-
return
|
66
|
-
|
67
|
-
|
68
|
-
return OpenStruct.new(:method_sym => :add ,:dao => dao, :args => [ids])
|
69
|
-
# return lambda { dao.add ids }
|
65
|
+
return Patriarch::RedisInstruction.new(dao,:add,[ids,time])
|
66
|
+
else
|
67
|
+
return Patriarch::RedisInstruction.new(dao,:add,[ids])
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -29,102 +29,105 @@ class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
|
29
29
|
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
30
30
|
|
31
31
|
if my_behaviours.include? behaviour_symbol
|
32
|
-
if my_behaviours[behaviour_symbol]
|
32
|
+
if my_behaviours[behaviour_symbol].first.size == 3
|
33
33
|
clean_tripartite_behaviour(calling_entity,behaviour,options)
|
34
|
-
|
34
|
+
elsif my_behaviours[behaviour_symbol].first.size == 2
|
35
35
|
clean_bipartite_behaviour(calling_entity,behaviour,options)
|
36
|
+
else
|
37
|
+
raise "Bad Behaviour declaration occured, no doublet or triplet are registered"
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
42
|
+
|
40
43
|
#:nodoc:
|
41
44
|
def clean_tripartite_behaviour(calling_entity,behaviour,options={})
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# Compute names based on conventions
|
46
|
-
progressive_present_behaviour =
|
47
|
-
(Verbs::Conjugator.conjugate behaviour_symbol, :aspect => :progressive).split(/ /).last
|
45
|
+
my_class = calling_entity.class
|
46
|
+
tripartite_behaviour = my_class.patriarch_behaviours[behaviour.to_s.underscore.to_sym]
|
48
47
|
|
49
48
|
transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym)
|
50
49
|
options = { :transac => transac, :stop_execution => true}
|
50
|
+
|
51
|
+
tripartite_behaviour.each do |protagonists|
|
52
|
+
clean_tripartite_behaviour_for_actor(calling_entity,behaviour,protagonists,options) if protagonists.first == my_class
|
53
|
+
clean_tripartite_behaviour_for_target(calling_entity,behaviour,protagonists,options) if protagonists.second == my_class
|
54
|
+
clean_tripartite_behaviour_for_medium(calling_entity,behaviour,protagonists,options) if protagonists.third == my_class
|
55
|
+
end
|
51
56
|
|
52
|
-
|
57
|
+
transac
|
58
|
+
end #clean_tripartite_behaviour
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
acted_on_models.each do |acted_on_model|
|
59
|
-
via_models.each do |via_model|
|
60
|
-
calling_entity.send("#{acted_on_model.to_s.tableize}_i_#{behaviour.to_s}_via_#{via_model.to_s.tableize}", :with_medium => true).each do |tripartite_hash|
|
61
|
-
target_i_behaved_on = Array(acted_on_model.to_s.classify.constantize.find(tripartite_hash[:target])).first
|
62
|
-
medium_for_behaviour = Array(via_model.to_s.classify.constantize.find(tripartite_hash[:medium])).first
|
63
|
-
calling_entity.send(Patriarch.undo(behaviour.to_s).underscore,medium_for_behaviour,target_i_behaved_on,options)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
60
|
+
#:nodoc:
|
61
|
+
def clean_bipartite_behaviour(calling_entity,behaviour,options={})
|
62
|
+
my_class = calling_entity.class
|
63
|
+
bipartite_behaviour = my_class.patriarch_behaviours[behaviour.to_s.underscore.to_sym]
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
targetted_by_models = my_behaviours[behaviour_symbol][:by]
|
72
|
-
via_models = my_behaviours[behaviour_symbol][:via]
|
73
|
-
targetted_by_models.each do |targetted_by_model|
|
74
|
-
via_models.each do |via_model|
|
75
|
-
calling_entity.send("#{targetted_by_model.to_s.tableize}_#{progressive_present_behaviour}_me_via_#{via_model.to_s.tableize}", :with_medium => true).each do |tripartite_hash|
|
76
|
-
#
|
77
|
-
actor_that_behaved_on_me = Array(targetted_by_model.to_s.classify.constantize.find(tripartite_hash[:actor])).first
|
78
|
-
medium_for_behaviour = Array(via_model.to_s.classify.constantize.find(tripartite_hash[:medium])).first
|
79
|
-
#
|
80
|
-
actor_that_behaved_on_me.send(Patriarch.undo(behaviour.to_s).underscore,medium_for_behaviour,calling_entity,options)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
65
|
+
transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym)
|
66
|
+
options = { :transac => transac, :stop_execution => true}
|
85
67
|
|
86
|
-
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
end # if my_behaviours.include?
|
68
|
+
bipartite_behaviour.each do |protagonists|
|
69
|
+
clean_bipartite_behaviour_for_actor(calling_entity,behaviour,protagonists,options) if protagonists.first == my_class
|
70
|
+
clean_bipartite_behaviour_for_target(calling_entity,behaviour,protagonists,options) if protagonists.second == my_class
|
71
|
+
end
|
91
72
|
|
92
73
|
transac
|
93
|
-
end #
|
74
|
+
end # #clean_bipartite_behaviour
|
94
75
|
|
95
|
-
|
96
|
-
|
97
|
-
|
76
|
+
protected
|
77
|
+
|
78
|
+
def clean_bipartite_behaviour_for_actor(calling_entity,behaviour,protagonists,options)
|
79
|
+
acted_on_model = protagonists.second
|
80
|
+
calling_entity.send("#{acted_on_model.to_s.tableize}_i_#{behaviour.to_s}").each do |target_i_behaved_on|
|
81
|
+
calling_entity.send(Patriarch.undo(behaviour.to_s).underscore,target_i_behaved_on,options)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def clean_bipartite_behaviour_for_target(calling_entity,behaviour,protagonists,options)
|
86
|
+
# Dealing with passive behaviour
|
98
87
|
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
99
88
|
|
100
89
|
# Compute names based on conventions
|
101
90
|
progressive_present_behaviour =
|
102
91
|
(Verbs::Conjugator.conjugate behaviour_symbol, :aspect => :progressive).split(/ /).last
|
103
92
|
|
104
|
-
|
105
|
-
|
93
|
+
targetted_by_model = protagonists.first
|
94
|
+
calling_entity.send("#{targetted_by_model.to_s.tableize}_#{progressive_present_behaviour}_me").each do |actor_that_behaved_on_me|
|
95
|
+
actor_that_behaved_on_me.send(Patriarch.undo(behaviour.to_s).underscore,calling_entity,options)
|
96
|
+
end
|
97
|
+
end
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
# Dealing with active behaviour
|
118
|
-
if my_behaviours[behaviour_symbol][:on]
|
119
|
-
acted_on_models = my_behaviours[behaviour_symbol][:on]
|
120
|
-
acted_on_models.each do |acted_on_model|
|
121
|
-
calling_entity.send("#{acted_on_model.to_s.tableize}_i_#{behaviour.to_s}").each do |target_i_behaved_on|
|
122
|
-
calling_entity.send(Patriarch.undo(behaviour.to_s).underscore,target_i_behaved_on,options)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end # if my_behaviours.include?
|
99
|
+
def clean_tripartite_behaviour_for_actor(calling_entity,behaviour,protagonists,options)
|
100
|
+
# Dealing with active behaviour
|
101
|
+
acted_on_model = protagonists.second
|
102
|
+
via_model = protagonists.third
|
103
|
+
calling_entity.send("#{acted_on_model.to_s.tableize}_i_#{behaviour.to_s}_via_#{via_model.to_s.tableize}", :with_medium => true).each do |tripartite_hash|
|
104
|
+
target_i_behaved_on = Array(acted_on_model.find(tripartite_hash[:target])).first
|
105
|
+
medium_for_behaviour = Array(via_model.find(tripartite_hash[:medium])).first
|
106
|
+
calling_entity.send(Patriarch.undo(behaviour.to_s).underscore,medium_for_behaviour,target_i_behaved_on,options)
|
107
|
+
end
|
108
|
+
end
|
127
109
|
|
128
|
-
|
129
|
-
|
130
|
-
|
110
|
+
def clean_tripartite_behaviour_for_target(calling_entity,behaviour,protagonists,options)
|
111
|
+
# Dealing with passive behaviour
|
112
|
+
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
113
|
+
|
114
|
+
# Compute names based on conventions
|
115
|
+
progressive_present_behaviour =
|
116
|
+
(Verbs::Conjugator.conjugate behaviour_symbol, :aspect => :progressive).split(/ /).last
|
117
|
+
|
118
|
+
targetted_by_model = protagonists.first
|
119
|
+
via_model = protagonists.third
|
120
|
+
calling_entity.send("#{targetted_by_model.to_s.tableize}_#{progressive_present_behaviour}_me_via_#{via_model.to_s.tableize}", :with_medium => true).each do |tripartite_hash|
|
121
|
+
actor_that_behaved_on_me = Array(targetted_by_model.find(tripartite_hash[:actor])).first
|
122
|
+
medium_for_behaviour = Array(via_model.find(tripartite_hash[:medium])).first
|
123
|
+
actor_that_behaved_on_me.send(Patriarch.undo(behaviour.to_s).underscore,medium_for_behaviour,calling_entity,options)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def clean_tripartite_behaviour_for_medium(calling_entity,behaviour,protagonists,options)
|
128
|
+
# do nothing. Not implemented yet.
|
129
|
+
# TODO sort this bizarre thing
|
130
|
+
# Previous version comment said => #do nothing, we do not take care of data relative to medium ...
|
131
|
+
end
|
132
|
+
|
133
|
+
end # class Patriarch ...
|
@@ -15,7 +15,7 @@ module Patriarch
|
|
15
15
|
|
16
16
|
forwarded_methods_syms = [:relation_type,:actor_type,:target_type,:medium_type,
|
17
17
|
:actor_id,:target_id,:medium_id,
|
18
|
-
:context,:actor,:target,:medium]
|
18
|
+
:context,:actor,:target,:medium,:protagonists_models]
|
19
19
|
|
20
20
|
# Forward methods that are not this transaction's job to step object
|
21
21
|
forwarded_methods_syms.each do |method_sym|
|
@@ -43,22 +43,25 @@ module Patriarch
|
|
43
43
|
target_type.to_s.camelize.constantize.find target_id
|
44
44
|
end
|
45
45
|
|
46
|
+
def protagonists_models
|
47
|
+
# By convention always actor, target, model for tripartite and
|
48
|
+
# actor, model for bipartite
|
49
|
+
[actor,target,medium].compact.map(&:class)
|
50
|
+
end
|
51
|
+
|
46
52
|
# execute the redis instructions embedded into this step against
|
47
53
|
# instructions are a dao, a method to call upon and its argument embedded into a OpenStruct
|
48
54
|
# before Patriarch 0.2.5, was embedded directly in a proc, was a complete failure for unknown reasons
|
49
55
|
# Patriach::Transaction use this method on each of the steps it registered within a multi block
|
50
56
|
def execute
|
51
|
-
queue.each do |
|
52
|
-
|
53
|
-
dao, method_sym, args = [os.dao,os.method_sym,os.args]
|
54
|
-
dao.send(method_sym,*args)
|
55
|
-
# deprecated, remove this : redis_instruction.call
|
57
|
+
queue.each do |redis_struct_instruction|
|
58
|
+
redis_struct_instruction.execute
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
|
-
# @param [
|
60
|
-
def add_to_queue(
|
61
|
-
queue <<
|
62
|
+
# @param [Patriarch::RedisInstruction] ostruct dao with parameters and method to call embedded here to be processed later
|
63
|
+
def add_to_queue(struct)
|
64
|
+
queue << struct
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
data/lib/patriarch/version.rb
CHANGED
@@ -22,7 +22,7 @@ describe Patriarch::DAOServices::BipartiteRelationshipBuilderService do
|
|
22
22
|
it "shall insert processable lambdas into queues when create is called" do
|
23
23
|
expect{
|
24
24
|
instance.create(@transac)
|
25
|
-
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a?
|
25
|
+
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a? Patriarch::RedisInstruction}.size }.by(2)
|
26
26
|
|
27
27
|
expect{
|
28
28
|
@transac.transaction_queue.each do |redis_ostruct_instruction|
|
@@ -36,7 +36,7 @@ describe Patriarch::DAOServices::BipartiteRelationshipBuilderService do
|
|
36
36
|
it "shall insert processable lambdas into queues when destroy is called" do
|
37
37
|
expect{
|
38
38
|
instance.destroy(@transac)
|
39
|
-
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a?
|
39
|
+
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a? Patriarch::RedisInstruction}.size }.by(2)
|
40
40
|
|
41
41
|
expect{
|
42
42
|
@transac.transaction_queue.each do |redis_ostruct_instruction|
|
@@ -24,7 +24,7 @@ describe Patriarch::DAOServices::TripartiteRelationshipBuilderService do
|
|
24
24
|
it "shall insert processable lambdas into queues when create is called" do
|
25
25
|
expect{
|
26
26
|
instance.create(@transac)
|
27
|
-
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a?
|
27
|
+
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a? Patriarch::RedisInstruction}.size }.by(3)
|
28
28
|
|
29
29
|
expect{
|
30
30
|
@transac.transaction_queue.each do |redis_ostruct_instruction|
|
@@ -38,7 +38,7 @@ describe Patriarch::DAOServices::TripartiteRelationshipBuilderService do
|
|
38
38
|
it "shall insert processable lambdas into queues when destroy is called" do
|
39
39
|
expect{
|
40
40
|
instance.destroy(@transac)
|
41
|
-
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a?
|
41
|
+
}.to change{ @transac.transaction_queue.select{ |queue_element| queue_element.is_a? Patriarch::RedisInstruction}.size }.by(3)
|
42
42
|
|
43
43
|
expect{
|
44
44
|
@transac.transaction_queue.each do |redis_ostruct_instruction|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patriarch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: verbs
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/patriarch/dao_services/retriever_service.rb
|
167
167
|
- lib/patriarch/dao_services/tripartite_relationship_builder_service.rb
|
168
168
|
- lib/patriarch/manager_service.rb
|
169
|
+
- lib/patriarch/redis_instruction.rb
|
169
170
|
- lib/patriarch/service.rb
|
170
171
|
- lib/patriarch/tool_services/redis_cleaner_service.rb
|
171
172
|
- lib/patriarch/tool_services/redis_extractor_service.rb
|