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 +3 -0
- data/lib/enough_fields.rb +1 -0
- data/lib/enough_fields/attribute_value.rb +10 -5
- data/lib/enough_fields/attributes.rb +2 -2
- data/lib/enough_fields/monit_set.rb +19 -6
- data/lib/enough_fields/notification.rb +1 -1
- data/lib/enough_fields/version.rb +1 -1
- data/spec/enough_fields/enough_fields_spec.rb +3 -1
- metadata +3 -3
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
|
data/lib/enough_fields.rb
CHANGED
@@ -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
|
-
|
19
|
-
|
20
|
-
|
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?
|
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.
|
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
|
-
|
10
|
-
|
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,
|
25
|
+
results.each do |call_stack_klass, results|
|
15
26
|
call_stack, klass = *call_stack_klass
|
16
|
-
|
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
|
@@ -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
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|