From 9fa6f213d0a96a0f7ddc28b521174197e005c29c Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 17:29:28 +0200 Subject: [PATCH 1/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 2bf71c3..b834cc8 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -13,6 +13,10 @@ def fires(event_type, opts) opts[:on].each { |on| fires(event_type, opts.merge({:on => on})) } return end + if opts[:actor].kind_of?(Array) + opts[:actor].each { |actor| fires(event_type, opts.merge({:actor => actor})) } + return + end opts[:subject] = :self unless opts.has_key?(:subject) From 173c855cf0fc0d3fba869443b3a03ef49b987f24 Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 17:50:53 +0200 Subject: [PATCH 2/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index b834cc8..7b7cbbb 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -22,19 +22,27 @@ def fires(event_type, opts) method_name = :"fire_#{event_type}_after_#{opts[:on]}" define_method(method_name) do - create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| - if opts[sym] - if opts[sym].respond_to?(:call) - memo[sym] = opts[sym].call(self) - elsif opts[sym] == :self - memo[sym] = self - else - memo[sym] = send(opts[sym]) + opts[:actor] = [] << opts[:actor] unless opts[:actor].kind_of?(Array) + + opts[:actor].each do |actor| + + new_opts = opts.merge({:actor => actor}) + + create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| + if new_opts[sym] + if new_opts[sym].respond_to?(:call) + memo[sym] = new_opts[sym].call(self) + elsif new_opts[sym] == :self + memo[sym] = self + else + memo[sym] = send(new_opts[sym]) + end + end + memo end + create_options[:event_type] = event_type.to_s + end - memo - end - create_options[:event_type] = event_type.to_s TimelineEvent.create!(create_options) end From 77bdaf3f1bc7234ea1bb1f064be0a6ac987d2902 Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 17:55:31 +0200 Subject: [PATCH 3/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 7b7cbbb..7de37db 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -40,11 +40,10 @@ def fires(event_type, opts) end memo end + create_options[:event_type] = event_type.to_s - - end - - TimelineEvent.create!(create_options) + TimelineEvent.create!(create_options) + end end send(:"after_#{opts[:on]}", method_name, :if => opts[:if]) From e77ad3ce2083e3f0ef0489be25730e9adc601a0f Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 18:06:44 +0200 Subject: [PATCH 4/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 7de37db..4ab959a 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -12,11 +12,7 @@ def fires(event_type, opts) if opts[:on].kind_of?(Array) opts[:on].each { |on| fires(event_type, opts.merge({:on => on})) } return - end - if opts[:actor].kind_of?(Array) - opts[:actor].each { |actor| fires(event_type, opts.merge({:actor => actor})) } - return - end + end opts[:subject] = :self unless opts.has_key?(:subject) @@ -29,13 +25,13 @@ def fires(event_type, opts) new_opts = opts.merge({:actor => actor}) create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| - if new_opts[sym] - if new_opts[sym].respond_to?(:call) - memo[sym] = new_opts[sym].call(self) - elsif new_opts[sym] == :self + if opts[sym] + if opts[sym].respond_to?(:call) + memo[sym] = opts[sym].call(self) + elsif opts[sym] == :self memo[sym] = self else - memo[sym] = send(new_opts[sym]) + memo[sym] = send(opts[sym]) end end memo From 24b349be0fe5961723324435452814c4ab94a3d6 Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 18:13:55 +0200 Subject: [PATCH 5/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 4ab959a..24f8fbe 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -25,13 +25,17 @@ def fires(event_type, opts) new_opts = opts.merge({:actor => actor}) create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| - if opts[sym] - if opts[sym].respond_to?(:call) - memo[sym] = opts[sym].call(self) - elsif opts[sym] == :self + if new_opts[sym] + p 1 + if new_opts[sym].respond_to?(:call) + memo[sym] = new_opts[sym].call(self) + p 2 + elsif new_opts[sym] == :self memo[sym] = self + p 3 else - memo[sym] = send(opts[sym]) + memo[sym] = send(new_opts[sym]) + p 4 end end memo From 6f1d604e5a33a20260f4bc6188d361232bfa6a72 Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 18:24:05 +0200 Subject: [PATCH 6/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 24f8fbe..3640436 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -38,9 +38,10 @@ def fires(event_type, opts) p 4 end end + p "memo: #{memo}" memo end - + p "create_options: #{create_options}" create_options[:event_type] = event_type.to_s TimelineEvent.create!(create_options) end From 3c01e849b56af4e532e3ed497197d9d94d3669de Mon Sep 17 00:00:00 2001 From: wolfwizard Date: Mon, 19 Dec 2011 18:32:08 +0200 Subject: [PATCH 7/7] Update lib/timeline_fu/fires.rb --- lib/timeline_fu/fires.rb | 48 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/lib/timeline_fu/fires.rb b/lib/timeline_fu/fires.rb index 3640436..208a10d 100644 --- a/lib/timeline_fu/fires.rb +++ b/lib/timeline_fu/fires.rb @@ -12,43 +12,35 @@ def fires(event_type, opts) if opts[:on].kind_of?(Array) opts[:on].each { |on| fires(event_type, opts.merge({:on => on})) } return - end + end opts[:subject] = :self unless opts.has_key?(:subject) method_name = :"fire_#{event_type}_after_#{opts[:on]}" define_method(method_name) do - opts[:actor] = [] << opts[:actor] unless opts[:actor].kind_of?(Array) - - opts[:actor].each do |actor| - - new_opts = opts.merge({:actor => actor}) - - create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| - if new_opts[sym] - p 1 - if new_opts[sym].respond_to?(:call) - memo[sym] = new_opts[sym].call(self) - p 2 - elsif new_opts[sym] == :self - memo[sym] = self - p 3 - else - memo[sym] = send(new_opts[sym]) - p 4 - end - end - p "memo: #{memo}" - memo + create_options = [:actor, :subject, :secondary_subject].inject({}) do |memo, sym| + if opts[sym] + if opts[sym].respond_to?(:call) + memo[sym] = opts[sym].call(self) + elsif opts[sym] == :self + memo[sym] = self + else + memo[sym] = send(opts[sym]) end - p "create_options: #{create_options}" - create_options[:event_type] = event_type.to_s - TimelineEvent.create!(create_options) - end + end + memo + end + create_options[:event_type] = event_type.to_s + if create_options[:actor].kind_of?(Array) + create_options[:actor].each { |actor| TimelineEvent.create!(create_options.merge({:actor => actor})) } + else + TimelineEvent.create!(create_options) + end + end send(:"after_#{opts[:on]}", method_name, :if => opts[:if]) end end end -end +end \ No newline at end of file