enough_fields 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -26,6 +26,7 @@ EnoughFields won't do ANYTHING unless you tell it to explicitly. Append to <code
26
26
  The notifier of enough_fields is a wrap of "uniform_notifier":https://github.com/flyerhzm/uniform_notifier
27
27
 
28
28
  The code above will enable all six of the EnoughFields notification systems:
29
+
29
30
  * <code>EnoughFields.enable</code>: enable EnoughFields plugin/gem, otherwise do nothing
30
31
  * <code>EnoughFields.alert</code>: pop up a JavaScript alert in the browser
31
32
  * <code>EnoughFields.enough_fields_logger</code>: log to the EnoughFields log file (Rails.root/log/enough_fields.log)
@@ -39,6 +40,7 @@ Growl Support
39
40
  -------------
40
41
 
41
42
  To get Growl support up-and-running for EnoughFields, follow the steps below:
43
+
42
44
  * Install the ruby-growl gem: <code>gem install ruby-growl</code>
43
45
  * Open the Growl preference pane in Systems Preferences
44
46
  * Click the "Network" tab
@@ -55,6 +57,7 @@ XMPP/Jabber Support
55
57
  -------------------
56
58
 
57
59
  To get XMPP support up-and-running for EnoughFields, follow the steps below:
60
+
58
61
  * Install the xmpp4r gem: <code>gem install xmpp4r</code>
59
62
  * Make both the enough_fields and the recipient account add each other as contacts.
60
63
  This will require you to manually log into both accounts, add each other
@@ -66,6 +66,7 @@ module EnoughFields
66
66
 
67
67
  def end_request
68
68
  Thread.current[:monit_set] = nil
69
+ @notifications = nil
69
70
  end
70
71
 
71
72
  def notification?
@@ -1,23 +1,28 @@
1
1
  module EnoughFields
2
2
  class AttributeValue
3
3
  attr_reader :klass, :field, :call_stack
4
- attr_writer :call_stack
4
+ attr_writer :call_stack, :used
5
5
 
6
6
  def initialize(value, klass, field, call_stack)
7
7
  @value = value
8
8
  @klass = klass
9
- @field = field
9
+ @field = field.to_sym
10
10
  @call_stack = call_stack
11
+ @used = false
11
12
  end
12
13
 
13
14
  def to_value
14
15
  @value
15
16
  end
16
17
 
18
+ def used?
19
+ @used == true
20
+ end
21
+
17
22
  def eql?( other )
18
- self.klass == other.klass &&
19
- self.field == other.field &&
20
- self.call_stack == other.call_stack
23
+ self.klass == other.klass &&
24
+ self.field == other.field &&
25
+ self.call_stack == other.call_stack
21
26
  end
22
27
 
23
28
  def hash
@@ -13,7 +13,7 @@ module EnoughFields
13
13
 
14
14
  hash = super
15
15
  hash.each do |key, value|
16
- next if key.is_a? Array
16
+ next if key.is_a?(Array) || [:_id, :_type].include?(key.to_sym)
17
17
  attribute_value = AttributeValue.new(value, @klass, key, caller.find_all { |c| c.index Rails.root })
18
18
  hash[ key ] = attribute_value
19
19
  Thread.current[:monit_set] << attribute_value
@@ -26,7 +26,7 @@ module EnoughFields
26
26
  return super unless Thread.current[:monit_set]
27
27
 
28
28
  if super && super.is_a?(AttributeValue)
29
- super.call_stack = nil
29
+ super.used = true
30
30
  super.to_value
31
31
  else
32
32
  super
@@ -1,19 +1,32 @@
1
1
  require 'set'
2
2
 
3
3
  module EnoughFields
4
+ class Result
5
+ attr_accessor :field, :used
6
+
7
+ def initialize(field, used)
8
+ @field = field
9
+ @used = used
10
+ end
11
+
12
+ def used?
13
+ used == true
14
+ end
15
+ end
16
+
4
17
  class MonitSet < Set
5
18
 
6
19
  def check_notifications
7
20
  results = {}
8
21
  self.each do |attribute_value|
9
- if attribute_value.call_stack
10
- results[ [attribute_value.call_stack, attribute_value.klass] ] ||= []
11
- results[ [attribute_value.call_stack, attribute_value.klass] ] << attribute_value.field
12
- end
22
+ results[ [attribute_value.call_stack, attribute_value.klass] ] ||= []
23
+ results[ [attribute_value.call_stack, attribute_value.klass] ] << Result.new(attribute_value.field, attribute_value.used?)
13
24
  end
14
- results.each do |call_stack_klass, fields|
25
+ results.each do |call_stack_klass, results|
15
26
  call_stack, klass = *call_stack_klass
16
- EnoughFields.add_notification(call_stack, klass, fields)
27
+ if results.find { |result| !result.used? }
28
+ EnoughFields.add_notification(call_stack, klass, results.find_all { |result| result.used? }.collect(&:field))
29
+ end
17
30
  end
18
31
  end
19
32
  end
@@ -9,7 +9,7 @@ module EnoughFields
9
9
  end
10
10
 
11
11
  def full_notice
12
- "add .only(#{(@klass.fields.keys - @fields).inspect}) for\n#{@call_stack.join("\n")}"
12
+ "add .only(:#{@fields.join(", :")}) for\n#{@call_stack.join("\n")}"
13
13
  end
14
14
 
15
15
  def notify_inline
@@ -1,3 +1,3 @@
1
1
  module EnoughFields
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,7 +19,9 @@ describe EnoughFields do
19
19
  EnoughFields.growl = true
20
20
  EnoughFields.start_request
21
21
  Thread.current[:monit_set] = EnoughFields::MonitSet.new
22
- p User.all.collect(&:email)
22
+ p User.all.collect {|user| [user.email, user.login]}
23
+
24
+ p User.only(:email).collect(&:email)
23
25
  # User.all.to_a
24
26
  if EnoughFields.notification?
25
27
  EnoughFields.perform_out_of_channel_notifications
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enough_fields
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang