patriarch 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +180 -9
- data/lib/generators/patriarch/templates/manager_service-tripartite.rb +10 -1
- data/lib/patriarch/authorization_service.rb +24 -13
- data/lib/patriarch/behaviours.rb +190 -128
- data/lib/patriarch/dao_services/bipartite_relationship_builder_service.rb +15 -1
- data/lib/patriarch/dao_services/redis_mapper_service.rb +56 -27
- data/lib/patriarch/dao_services/retriever_service.rb +27 -15
- data/lib/patriarch/dao_services/tripartite_relationship_builder_service.rb +24 -9
- data/lib/patriarch/manager_service.rb +1 -0
- data/lib/patriarch/service.rb +5 -2
- data/lib/patriarch/tool_services/redis_cleaner_service.rb +50 -37
- data/lib/patriarch/tool_services/redis_extractor_service.rb +35 -5
- data/lib/patriarch/transaction.rb +10 -3
- data/lib/patriarch/transaction_step.rb +13 -2
- data/lib/patriarch/version.rb +1 -1
- data/spec/lib/patriarch/tool_services/redis_cleaner_service_spec.rb +1 -1
- metadata +52 -17
@@ -1,6 +1,14 @@
|
|
1
1
|
require "redis/objects/sorted_sets"
|
2
2
|
|
3
|
+
# Patriarch::Transaction instances are composed of transaction steps that each represent
|
4
|
+
# a behaviour being triggered. RelationshipBuilderServices allow Services managing transaction
|
5
|
+
# flow to build transaction step correctly. This deals with transaction step needed to represent
|
6
|
+
# bipartite behaviours
|
3
7
|
class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::Service
|
8
|
+
|
9
|
+
# @param [Patriarch::Transaction] transaction_item
|
10
|
+
# Fills current transaction step of the Patriarch::Transaction argument passed with data needed
|
11
|
+
# later to execute transaction. This deals with "DO" behaviour steps
|
4
12
|
def create(transaction_item)
|
5
13
|
t = Time.now.to_f
|
6
14
|
dao_tab = Patriarch::DAOServices::RetrieverService.instance.call(transaction_item)
|
@@ -16,6 +24,9 @@ class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::S
|
|
16
24
|
transaction_item.add_to_queue ll
|
17
25
|
end
|
18
26
|
|
27
|
+
# @param [Patriarch::Transaction] transaction_item
|
28
|
+
# Fills current transaction step of the Patriarch::Transaction argument passed with data needed
|
29
|
+
# later to execute transaction. This deals with "UNDO" behaviour steps
|
19
30
|
def destroy(transaction_item)
|
20
31
|
dao_tab = Patriarch::DAOServices::RetrieverService.instance.call(transaction_item)
|
21
32
|
|
@@ -33,7 +44,10 @@ class Patriarch::DAOServices::BipartiteRelationshipBuilderService < Patriarch::S
|
|
33
44
|
end
|
34
45
|
|
35
46
|
protected
|
36
|
-
|
47
|
+
# @param [Redis::Objects] dao
|
48
|
+
# @param [Array] ids
|
49
|
+
# @param [Time] time
|
50
|
+
# Returns lambda objects that store a redis operation
|
37
51
|
def build_lambda_for_create(dao,id,time)
|
38
52
|
if dao.is_a? Redis::SortedSet
|
39
53
|
return lambda { dao.add id, time }
|
@@ -1,22 +1,30 @@
|
|
1
|
+
# This service is in charge of the redis mapping.
|
2
|
+
# When wanting to retrieve DAOs needed for a transaction, we may want to retrieve Redis DAO
|
3
|
+
# For each situation e.g. (in a given transaction, with a given protagonist that has an unique role), the
|
4
|
+
# service will return the configuration needed to achieve DAO build. Hence it enforces conventions
|
1
5
|
class Patriarch::DAOServices::RedisMapperService < Patriarch::Service
|
2
|
-
|
3
|
-
|
6
|
+
|
7
|
+
# @param [Patriach::Transaction]transaction the transaction being processed
|
8
|
+
# @param [Symbol] protagonist_type the type of the protagonist whose DAO is needed
|
9
|
+
# @return [Hash] hash with configuration needed to achieve DAO build
|
10
|
+
def call(transaction,protagonist_type)
|
11
|
+
|
4
12
|
# Getting symbols here ...
|
5
|
-
relation_type =
|
6
|
-
actor_type =
|
7
|
-
target_type =
|
8
|
-
medium_type =
|
9
|
-
|
13
|
+
relation_type = transaction.relation_type
|
14
|
+
actor_type = transaction.actor_type
|
15
|
+
target_type = transaction.target_type
|
16
|
+
medium_type = transaction.medium_type
|
17
|
+
|
10
18
|
relation_type_str = sanitize_relation_type(relation_type.to_s)
|
11
19
|
|
12
|
-
if
|
20
|
+
if transaction.tripartite?
|
13
21
|
if protagonist_type == :actor
|
14
22
|
redis_tripartite_config_for_actor(target_type,medium_type,relation_type_str)
|
15
23
|
elsif protagonist_type == :target
|
16
24
|
redis_tripartite_config_for_target(actor_type,medium_type,relation_type_str)
|
17
25
|
elsif protagonist_type == :medium
|
18
26
|
redis_tripartite_config_for_medium(actor_type,target_type,relation_type_str)
|
19
|
-
end
|
27
|
+
end
|
20
28
|
else
|
21
29
|
if protagonist_type == :actor
|
22
30
|
redis_bipartite_config_for_actor(target_type,relation_type_str)
|
@@ -26,53 +34,74 @@ class Patriarch::DAOServices::RedisMapperService < Patriarch::Service
|
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
37
|
+
# @param [String] target_model_name
|
38
|
+
# @param [String] relation_type_str
|
39
|
+
# @return [Hash] a hash containing configuration to build actor DAO used in bipartite transactions
|
29
40
|
def redis_bipartite_config_for_actor(target_model_name,relation_type_str)
|
30
|
-
# example : items_i_like ...
|
31
|
-
{
|
32
|
-
:type => "sorted_set",
|
41
|
+
# example : items_i_like ...
|
42
|
+
{
|
43
|
+
:type => "sorted_set",
|
33
44
|
:key => "patriarch_#{target_model_name.to_s.tableize}_i_#{relation_type_str}"
|
34
45
|
}
|
35
46
|
end
|
36
47
|
|
48
|
+
# @param [String] target_model_name
|
49
|
+
# @param [String] relation_type_str
|
50
|
+
# @return [Hash] a hash containing configuration to build target DAO used in bipartite transactions
|
37
51
|
def redis_bipartite_config_for_target(actor_model_name,relation_type_str)
|
38
52
|
# example : items_liking_me ...
|
39
|
-
{
|
40
|
-
:type => "sorted_set",
|
53
|
+
{
|
54
|
+
:type => "sorted_set",
|
41
55
|
:key => "patriarch_#{actor_model_name.to_s.tableize}_#{progressive_present(relation_type_str)}_me"
|
42
56
|
}
|
43
|
-
end
|
57
|
+
end
|
44
58
|
|
59
|
+
# @param [String] target_model_name
|
60
|
+
# @param [String] relation_type_str
|
61
|
+
# @return [Hash] a hash containing configuration to build actor DAO used in tripartite transactions
|
45
62
|
def redis_tripartite_config_for_actor(target_model_name,medium_model_name,relation_type_str)
|
46
|
-
{
|
47
|
-
:type => "sorted_set",
|
63
|
+
{
|
64
|
+
:type => "sorted_set",
|
48
65
|
:key => "patriarch_#{target_model_name.to_s.tableize}_i_#{relation_type_str}_via_#{medium_model_name.to_s.tableize}",
|
49
66
|
:options => { :marshal => true }
|
50
67
|
}
|
51
68
|
end
|
52
|
-
|
69
|
+
|
70
|
+
# @param [String] target_model_name
|
71
|
+
# @param [String] relation_type_str
|
72
|
+
# @return [Hash] a hash containing configuration to build medium DAO used in tripartite transactions
|
53
73
|
def redis_tripartite_config_for_medium(actor_model_name,target_model_name,relation_type_str)
|
54
|
-
{
|
55
|
-
:type => "sorted_set",
|
74
|
+
{
|
75
|
+
:type => "sorted_set",
|
56
76
|
:key => "patriarch_#{actor_model_name.to_s.tableize}_#{progressive_present(relation_type_str)}_#{target_model_name.to_s.tableize}_via_me",
|
57
|
-
:options => { :marshal => true }
|
58
|
-
}
|
77
|
+
:options => { :marshal => true }
|
78
|
+
}
|
59
79
|
end
|
60
80
|
|
81
|
+
# @param [String] target_model_name
|
82
|
+
# @param [String] relation_type_str
|
83
|
+
# @return [Hash] a hash containing configuration to build target DAO used in tripartite transactions
|
61
84
|
def redis_tripartite_config_for_target(actor_model_name,medium_model_name,relation_type_str)
|
62
85
|
# example : items_praising_me_via_comments
|
63
|
-
{
|
64
|
-
:type => "sorted_set",
|
86
|
+
{
|
87
|
+
:type => "sorted_set",
|
65
88
|
:key => "patriarch_#{actor_model_name.to_s.tableize}_#{progressive_present(relation_type_str)}_me_via_#{medium_model_name.to_s.tableize}",
|
66
|
-
:options => { :marshal => true }
|
67
|
-
}
|
89
|
+
:options => { :marshal => true }
|
90
|
+
}
|
68
91
|
end
|
69
92
|
|
93
|
+
# Little helper to put behaviour verbs to progressive form, relies on gem 'Verbs'
|
94
|
+
# @param [String] behaviour_verb the verb to conjugate
|
95
|
+
# @return [String] progressive form of behaviour_verb
|
70
96
|
def progressive_present(behaviour_verb)
|
71
97
|
# like becomes => liking
|
72
98
|
(Verbs::Conjugator.conjugate behaviour_verb.to_sym, :aspect => :progressive).split(/ /).last
|
73
99
|
end
|
74
100
|
|
101
|
+
# Helper to sanitize relation type string that is equivalent to behaviour verb with a prefix to its base root.
|
102
|
+
# DAO and DB storage are agnostic about what kind of operation is being performed on them, hence we dont
|
103
|
+
# need to know if it will be an undo or a 'do'.
|
75
104
|
def sanitize_relation_type(relation_type)
|
76
105
|
relation_type.sub(/^undo_/,'')
|
77
106
|
end
|
78
|
-
end
|
107
|
+
end
|
@@ -3,37 +3,45 @@ require 'redis/objects/sorted_sets'
|
|
3
3
|
class InvalidRedisTypeException < Exception
|
4
4
|
end
|
5
5
|
|
6
|
+
# Services managing transactions must not know how the database layer is structured.
|
7
|
+
# We thus provide DAO through this RetrieverService and let them know about the interface of the DAOs
|
6
8
|
class Patriarch::DAOServices::RetrieverService < Patriarch::Service
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
# @return [Hash] hash containing DAOs for RelationshipBuilderServices to toy with
|
11
|
+
# @param [Patriarch::Transaction] transaction_item
|
12
|
+
# Only public method of this service, does the work of retrieving DAOs for a given transaction step
|
13
|
+
def call(transaction_item)
|
9
14
|
result = {}
|
10
15
|
result[:actor] = instantiate_DAO_for_actor(transaction_item)
|
11
16
|
result[:target] = instantiate_DAO_for_target(transaction_item)
|
12
17
|
if transaction_item.tripartite?
|
13
|
-
result[:medium] = instantiate_DAO_for_medium(transaction_item)
|
18
|
+
result[:medium] = instantiate_DAO_for_medium(transaction_item)
|
14
19
|
end
|
15
|
-
result
|
20
|
+
result
|
16
21
|
end
|
17
22
|
|
18
23
|
protected
|
19
|
-
|
24
|
+
#:nodoc:
|
20
25
|
def get_DAO_info_for_actor(transaction_item)
|
21
26
|
Patriarch::DAOServices::RedisMapperService.instance.call(transaction_item,:actor)
|
22
27
|
end
|
23
28
|
|
24
|
-
|
29
|
+
#:nodoc
|
30
|
+
def get_DAO_info_for_target(transaction_item)
|
25
31
|
Patriarch::DAOServices::RedisMapperService.instance.call(transaction_item,:target)
|
26
32
|
end
|
27
|
-
|
33
|
+
|
34
|
+
#:nodoc
|
28
35
|
def get_DAO_info_for_medium(transaction_item)
|
29
36
|
Patriarch::DAOServices::RedisMapperService.instance.call(transaction_item,:medium)
|
30
37
|
end
|
31
38
|
|
39
|
+
#:nodoc:
|
32
40
|
def instantiate_DAO_for_actor(transaction_item)
|
33
|
-
dao_info = get_DAO_info_for_actor(transaction_item)
|
41
|
+
dao_info = get_DAO_info_for_actor(transaction_item)
|
34
42
|
actor_id = transaction_item.actor_id
|
35
43
|
actor_type = transaction_item.actor_type
|
36
|
-
|
44
|
+
|
37
45
|
if Redis::Objects.constants.map(&:to_s).include?("#{dao_info[:type].pluralize.camelize}")
|
38
46
|
redis_dao_class = "Redis::#{dao_info[:type].camelize}".constantize
|
39
47
|
else
|
@@ -42,12 +50,14 @@ class Patriarch::DAOServices::RetrieverService < Patriarch::Service
|
|
42
50
|
|
43
51
|
redis_dao_class.new("#{actor_type}:#{actor_id}:#{dao_info[:key]}",dao_info[:options])
|
44
52
|
end
|
45
|
-
|
53
|
+
|
54
|
+
|
55
|
+
#:nodoc:
|
46
56
|
def instantiate_DAO_for_medium(transaction_item)
|
47
|
-
dao_info = get_DAO_info_for_medium(transaction_item)
|
57
|
+
dao_info = get_DAO_info_for_medium(transaction_item)
|
48
58
|
medium_id = transaction_item.medium_id
|
49
59
|
medium_type = transaction_item.medium_type
|
50
|
-
|
60
|
+
|
51
61
|
if Redis::Objects.constants.map(&:to_s).include?("#{dao_info[:type].pluralize.camelize}")
|
52
62
|
redis_dao_class = "Redis::#{dao_info[:type].camelize}".constantize
|
53
63
|
else
|
@@ -55,19 +65,21 @@ class Patriarch::DAOServices::RetrieverService < Patriarch::Service
|
|
55
65
|
end
|
56
66
|
|
57
67
|
redis_dao_class.new("#{medium_type}:#{medium_id}:#{dao_info[:key]}",dao_info[:options])
|
58
|
-
end
|
68
|
+
end
|
69
|
+
|
59
70
|
|
71
|
+
#:nodoc:
|
60
72
|
def instantiate_DAO_for_target(transaction_item)
|
61
73
|
dao_info = get_DAO_info_for_target(transaction_item)
|
62
74
|
target_id = transaction_item.target_id
|
63
|
-
target_type = transaction_item.target_type
|
75
|
+
target_type = transaction_item.target_type
|
64
76
|
|
65
77
|
if Redis::Objects.constants.map(&:to_s).include?("#{dao_info[:type].pluralize.camelize}")
|
66
78
|
redis_dao_class = "Redis::#{dao_info[:type].camelize}".constantize
|
67
79
|
else
|
68
80
|
raise InvalidRedisTypeException, "Redis constants available were #{Redis::Objects.constants} and supplied type was #{dao_info[:type]}"
|
69
81
|
end
|
70
|
-
redis_dao_class.new("#{target_type}:#{target_id}:#{dao_info[:key]}",dao_info[:options])
|
82
|
+
redis_dao_class.new("#{target_type}:#{target_id}:#{dao_info[:key]}",dao_info[:options])
|
71
83
|
end
|
72
84
|
end
|
73
85
|
|
@@ -1,33 +1,45 @@
|
|
1
1
|
require "redis/objects/sorted_sets"
|
2
2
|
|
3
|
+
|
4
|
+
# Patriarch::Transaction instances are composed of transaction steps that each represent
|
5
|
+
# a behaviour being triggered. RelationshipBuilderServices allow Services managing transaction
|
6
|
+
# flow to build transaction step correctly. This deals with transaction step needed to represent
|
7
|
+
# tripartite behaviours
|
3
8
|
class Patriarch::DAOServices::TripartiteRelationshipBuilderService < Patriarch::Service
|
9
|
+
|
10
|
+
# @param [Patriarch::Transaction] transaction_item
|
11
|
+
# Fills current transaction step of the Patriarch::Transaction argument passed with data needed
|
12
|
+
# later to execute transaction. This deals with "DO" behaviour steps
|
4
13
|
def create(transaction_item)
|
5
14
|
t = Time.now.to_f
|
6
15
|
dao_tab = Patriarch::DAOServices::RetrieverService.instance.call(transaction_item)
|
7
|
-
|
16
|
+
|
8
17
|
actor_dao = dao_tab[:actor]
|
9
18
|
target_dao = dao_tab[:target]
|
10
|
-
medium_dao = dao_tab[:medium]
|
19
|
+
medium_dao = dao_tab[:medium]
|
11
20
|
|
12
21
|
protagonist_ids = [transaction_item.actor_id,transaction_item.target_id,transaction_item.medium_id]
|
13
22
|
|
14
23
|
l = build_lambda_for_create(actor_dao,protagonist_ids,t)
|
15
24
|
ll = build_lambda_for_create(target_dao,protagonist_ids,t)
|
16
25
|
lll = build_lambda_for_create(medium_dao,protagonist_ids,t)
|
17
|
-
|
26
|
+
|
18
27
|
# care about that, should be encapsulated into a beautiful add_to_queue method
|
19
28
|
transaction_item.add_to_queue l
|
20
29
|
transaction_item.add_to_queue ll
|
21
|
-
transaction_item.add_to_queue lll
|
30
|
+
transaction_item.add_to_queue lll
|
22
31
|
end
|
23
32
|
|
33
|
+
# @param [Patriarch::Transaction] transaction_item
|
34
|
+
# Fills current transaction step of the Patriarch::Transaction argument passed with data needed
|
35
|
+
# later to execute transaction. This deals with "UNDO" behaviour steps
|
24
36
|
def destroy(transaction_item)
|
25
37
|
dao_tab = Patriarch::DAOServices::RetrieverService.instance.call(transaction_item)
|
26
|
-
|
38
|
+
|
27
39
|
actor_dao = dao_tab[:actor]
|
28
40
|
target_dao = dao_tab[:target]
|
29
|
-
medium_dao = dao_tab[:medium]
|
30
|
-
|
41
|
+
medium_dao = dao_tab[:medium]
|
42
|
+
|
31
43
|
protagonist_ids = [transaction_item.actor_id,transaction_item.target_id,transaction_item.medium_id]
|
32
44
|
|
33
45
|
l = lambda { actor_dao.delete protagonist_ids }
|
@@ -36,11 +48,14 @@ class Patriarch::DAOServices::TripartiteRelationshipBuilderService < Patriarch::
|
|
36
48
|
|
37
49
|
transaction_item.add_to_queue l
|
38
50
|
transaction_item.add_to_queue ll
|
39
|
-
transaction_item.add_to_queue lll
|
51
|
+
transaction_item.add_to_queue lll
|
40
52
|
end
|
41
53
|
|
42
54
|
protected
|
43
|
-
|
55
|
+
# @param [Redis::Objects] dao
|
56
|
+
# @param [Array] ids
|
57
|
+
# @param [Time] time
|
58
|
+
# Returns lambda objects that store a redis operation
|
44
59
|
def build_lambda_for_create(dao,ids,time)
|
45
60
|
if dao.is_a? Redis::SortedSet
|
46
61
|
return lambda { dao.add ids, time }
|
data/lib/patriarch/service.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
# Adding behaviours to classes through Patriarch induces writes in Redis Database
|
2
|
+
# What happens when we want to destroy an item is that it fires ActiveRecord::Callbacks to deal
|
3
|
+
# with this kind of stuff. We build a transaction item whose execute would clean redis stuff
|
4
|
+
# but do nothing until commit happens in case SQL aborts.
|
5
|
+
# This service takes care of building clean items
|
1
6
|
class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
2
|
-
|
3
|
-
#
|
7
|
+
|
8
|
+
# @param [Object] calling_entity the entity calling the clean upon itself
|
9
|
+
# @param [Object] options various options we may want to pass, used here to transmit a transaction item if a clean transaction wraps all the clean
|
10
|
+
# @return [Patriarch::Transaction] returns a transaction item that is either built from scratch or was passed through options and has been completed
|
4
11
|
def clean_all(calling_entity,options={})
|
5
12
|
transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_all".to_sym)
|
6
13
|
options = { :transac => transac }
|
@@ -12,11 +19,17 @@ class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
|
12
19
|
transac
|
13
20
|
end
|
14
21
|
|
22
|
+
# @return [Patriarch::Transaction] returns a transaction item that is either built from scratch or was passed through options and has been completed
|
23
|
+
# @param [Object] calling_entity the entity calling the clean upon itself
|
24
|
+
# @param [Object] behaviour the behaviour the entity wants to clean
|
25
|
+
# @param [Object] options various options we may want to pass, used here to transmit a transaction item if a clean transaction wraps all the clean
|
26
|
+
# behaviours so it runs once and not multiple transactions.
|
15
27
|
def clean_behaviour(calling_entity,behaviour,options={})
|
16
28
|
my_behaviours = calling_entity.class.patriarch_behaviours
|
17
|
-
|
18
|
-
|
19
|
-
|
29
|
+
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
30
|
+
|
31
|
+
if my_behaviours.include? behaviour_symbol
|
32
|
+
if my_behaviours[behaviour_symbol][:medium_between] || my_behaviours[behaviour_symbol][:via]
|
20
33
|
clean_tripartite_behaviour(calling_entity,behaviour,options)
|
21
34
|
else
|
22
35
|
clean_bipartite_behaviour(calling_entity,behaviour,options)
|
@@ -24,24 +37,24 @@ class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
|
24
37
|
end
|
25
38
|
end
|
26
39
|
|
27
|
-
|
28
|
-
#Copiepat
|
40
|
+
#:nodoc:
|
29
41
|
def clean_tripartite_behaviour(calling_entity,behaviour,options={})
|
30
42
|
my_behaviours = calling_entity.class.patriarch_behaviours
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
43
|
+
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
44
|
+
|
45
|
+
# Compute names based on conventions
|
46
|
+
progressive_present_behaviour =
|
47
|
+
(Verbs::Conjugator.conjugate behaviour_symbol, :aspect => :progressive).split(/ /).last
|
35
48
|
|
36
49
|
transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym)
|
37
50
|
options = { :transac => transac, :stop_execution => true}
|
38
51
|
|
39
|
-
if my_behaviours.include?
|
52
|
+
if my_behaviours.include? behaviour_symbol
|
40
53
|
|
41
54
|
# Dealing with active behaviour
|
42
|
-
if my_behaviours[
|
43
|
-
acted_on_models = my_behaviours[
|
44
|
-
via_models = my_behaviours[
|
55
|
+
if my_behaviours[behaviour_symbol][:on]
|
56
|
+
acted_on_models = my_behaviours[behaviour_symbol][:on]
|
57
|
+
via_models = my_behaviours[behaviour_symbol][:via]
|
45
58
|
acted_on_models.each do |acted_on_model|
|
46
59
|
via_models.each do |via_model|
|
47
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|
|
@@ -52,13 +65,13 @@ class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
|
52
65
|
end
|
53
66
|
end
|
54
67
|
end
|
55
|
-
|
68
|
+
|
56
69
|
# Dealing with passive behaviour
|
57
|
-
if my_behaviours[
|
58
|
-
targetted_by_models = my_behaviours[
|
59
|
-
via_models = my_behaviours[
|
70
|
+
if my_behaviours[behaviour_symbol][:by]
|
71
|
+
targetted_by_models = my_behaviours[behaviour_symbol][:by]
|
72
|
+
via_models = my_behaviours[behaviour_symbol][:via]
|
60
73
|
targetted_by_models.each do |targetted_by_model|
|
61
|
-
via_models.each do |via_model|
|
74
|
+
via_models.each do |via_model|
|
62
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|
|
63
76
|
#
|
64
77
|
actor_that_behaved_on_me = Array(targetted_by_model.to_s.classify.constantize.find(tripartite_hash[:actor])).first
|
@@ -71,46 +84,46 @@ class Patriarch::ToolServices::RedisCleanerService < Patriarch::Service
|
|
71
84
|
end
|
72
85
|
|
73
86
|
# Dealing with medium behaviour
|
74
|
-
if my_behaviours[
|
87
|
+
if my_behaviours[behaviour_symbol][:medium_between]
|
75
88
|
#do nothing, we do not take care of data relative to medium ...
|
76
|
-
end
|
89
|
+
end
|
77
90
|
end # if my_behaviours.include?
|
78
91
|
|
79
|
-
transac
|
92
|
+
transac
|
80
93
|
end #clean_tripartite_behaviour
|
81
94
|
|
82
|
-
|
83
|
-
|
95
|
+
#:nodoc:
|
84
96
|
def clean_bipartite_behaviour(calling_entity,behaviour,options={})
|
85
97
|
my_behaviours = calling_entity.class.patriarch_behaviours
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
98
|
+
behaviour_symbol = behaviour.to_s.underscore.to_sym
|
99
|
+
|
100
|
+
# Compute names based on conventions
|
101
|
+
progressive_present_behaviour =
|
102
|
+
(Verbs::Conjugator.conjugate behaviour_symbol, :aspect => :progressive).split(/ /).last
|
90
103
|
|
91
104
|
transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym)
|
92
105
|
options = { :transac => transac, :stop_execution => true}
|
93
106
|
|
94
|
-
if my_behaviours.include?
|
107
|
+
if my_behaviours.include? behaviour_symbol
|
95
108
|
# Dealing with passive behaviour
|
96
|
-
if my_behaviours[
|
97
|
-
|
98
|
-
|
99
|
-
calling_entity.send("#{
|
109
|
+
if my_behaviours[behaviour_symbol][:by]
|
110
|
+
targeted_by_models = my_behaviours[behaviour_symbol][:by]
|
111
|
+
targeted_by_models.each do |targeted_by_model|
|
112
|
+
calling_entity.send("#{targeted_by_model.to_s.tableize}_#{progressive_present_behaviour}_me").each do |target_that_behaved_on_me|
|
100
113
|
target_that_behaved_on_me.send(Patriarch.undo(behaviour.to_s).underscore,calling_entity,options)
|
101
114
|
end
|
102
115
|
end
|
103
116
|
end
|
104
117
|
# Dealing with active behaviour
|
105
|
-
if my_behaviours[
|
106
|
-
acted_on_models = my_behaviours[
|
118
|
+
if my_behaviours[behaviour_symbol][:on]
|
119
|
+
acted_on_models = my_behaviours[behaviour_symbol][:on]
|
107
120
|
acted_on_models.each do |acted_on_model|
|
108
121
|
calling_entity.send("#{acted_on_model.to_s.tableize}_i_#{behaviour.to_s}").each do |target_i_behaved_on|
|
109
122
|
calling_entity.send(Patriarch.undo(behaviour.to_s).underscore,target_i_behaved_on,options)
|
110
123
|
end
|
111
124
|
end
|
112
125
|
end
|
113
|
-
|
126
|
+
|
114
127
|
|
115
128
|
end # if my_behaviours.include?
|
116
129
|
|