extraextra 0.1.2 → 0.2.0

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.rdoc CHANGED
@@ -29,13 +29,14 @@ It can be cloned via
29
29
 
30
30
  == Requirements
31
31
 
32
- * **Ruby 1.9** Sorry for you 1.8 people, 1.9 is the current version of Ruby.
33
- * **mongo** If you're going to use MongoDB...
32
+ * *Ruby-1.9* Sorry for you 1.8 people, 1.9 is the current version of Ruby.
33
+ I test with 1.9.2.
34
+ * *mongo* If you're going to use MongoDB...
34
35
 
35
36
  == Usage
36
37
 
37
- The first thing you'll need to do is configure EXTRA! EXTRA! to use your
38
- MongoDB installation.
38
+ The first thing you'll need to do is configure EXTRA! EXTRA! to connect to
39
+ your MongoDB:
39
40
 
40
41
  Extra::Extra.source :host => "localhost", :port => "1337"
41
42
 
@@ -51,8 +52,8 @@ or
51
52
 
52
53
  $ Extra::Extra.the_scoop user
53
54
 
54
- This returns an array of Extra objects. To find out more about a particular
55
- Extra:
55
+ This returns an array of Extra objects. To find out more about a particular
56
+ Extra:
56
57
 
57
58
  $ extra = Extra::Extra::! :sports, user, "hit a home run!"
58
59
 
@@ -69,8 +70,10 @@ This returns an array of Extra objects. To find out more about a particular
69
70
  $ extra.to_s
70
71
  => "Steve hit a home run"
71
72
 
72
- The name in to_s comes from user#username. If you use something else...
73
- I'll provide a way to override this eventually.
73
+ Two things: 'who' instantiates the object by sending it the find message,
74
+ passing an id. So that has to be defined in your user object. Secondly, the
75
+ name in to_s comes from user#username. If you use something else... I'll
76
+ provide a way to override these eventually.
74
77
 
75
78
  To only see breaking news:
76
79
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/extraextra.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{extraextra}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Klabnik"]
data/lib/extra/extra.rb CHANGED
@@ -14,12 +14,26 @@ module Extra
14
14
  :what,
15
15
  :when
16
16
 
17
+ def initialize opts={}
18
+ self.category ||= opts['category']
19
+ self.who_id ||= opts['who_id']
20
+ self.who_name ||= opts['who_name']
21
+ self.who_class ||= opts['who_class']
22
+ self.what ||= opts['what']
23
+ self.when ||= opts['when']
24
+ end
25
+
17
26
  # For now, this is just a simple sentence describing what happened.
18
27
  # We'll see if something more complex makes sense later.
19
28
  def to_s
20
29
  "#{who_name} #{what}"
21
30
  end
22
31
 
32
+ #returns the instantiated object of whodunnit
33
+ def who
34
+ Object.const_get(who_class).find(who_id)
35
+ end
36
+
23
37
  class << self
24
38
  attr_accessor :db, :collection
25
39
 
@@ -39,12 +53,12 @@ module Extra
39
53
  def !(category, user, text)
40
54
 
41
55
  args = {
42
- category: category,
43
- who_id: user.id,
44
- who_name: user.username,
45
- who_class: user.class.to_s,
46
- what: text,
47
- when: Time.now.to_s
56
+ 'category' => category,
57
+ 'who_id' => user.id,
58
+ 'who_name' => user.username,
59
+ 'who_class' => user.class.to_s,
60
+ 'what' => text,
61
+ 'when' => Time.now.to_s
48
62
  }
49
63
  collection.insert args
50
64
  Extra.new args
@@ -58,6 +72,9 @@ module Extra
58
72
  ).collect{|args| Extra.new args }
59
73
 
60
74
  end
75
+
76
+ # aliasing a shorter name
77
+ alias :the_scoop :read_all_about_it
61
78
  end
62
79
 
63
80
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Extra::Extra do
4
- describe "#source" do
4
+ describe "self#source" do
5
5
  it "should exist" do
6
6
  Extra::Extra.respond_to?(:source).should == true
7
7
  end
@@ -25,14 +25,14 @@ describe Extra::Extra do
25
25
  #holy setup batman
26
26
  collection = mock("collection")
27
27
  Extra::Extra.should_receive(:collection).and_return(collection)
28
- collection.should_receive(:insert).with(:category => :breaking, :who_id => 1, :who_name => "steve", :who_class => 'User', :what => "hit a home run", :when => Time.now.to_s)
28
+ collection.should_receive(:insert).with('category' => :breaking, 'who_id' => 1, 'who_name' => "steve", 'who_class' => 'User', 'what' => "hit a home run", 'when' => Time.now.to_s)
29
29
 
30
30
  user = mock("User", :id => 1, :class => 'User', :username => "steve")
31
31
  Extra::Extra::! :breaking, user, "hit a home run"
32
32
  end
33
33
  end
34
34
 
35
- describe "#read_all_about_it" do
35
+ describe "self#read_all_about_it" do
36
36
 
37
37
  it "should exist" do
38
38
  Extra::Extra.respond_to?(:read_all_about_it).should == true
@@ -47,12 +47,32 @@ describe Extra::Extra do
47
47
  extras.length.should == 1
48
48
  ex = extras.first
49
49
  ex.category.should == extra.category
50
- ex.who_id.should == extra.who_id
51
- ex.who_name.should == extra.who_name
52
- ex.who_class.should == extra.who_class
50
+ ex.who_id.should == user.id
51
+ ex.who_name.should == user.username
52
+ ex.who_class.should == user.class.to_s
53
53
  ex.what.should == extra.what
54
54
  ex.when.should == extra.when
55
55
  ex.to_s.should == extra.to_s
56
56
  end
57
57
  end
58
+
59
+ describe "self#the_scoop" do
60
+ it "should exist" do
61
+ Extra::Extra.respond_to?(:the_scoop).should == true
62
+ end
63
+ end
64
+
65
+ describe "#who" do
66
+ it "should instantiate the object" do
67
+ user = Factory(:user)
68
+ Extra::Extra.source
69
+ extra = Extra::Extra::! :breaking, user, "hit a home run"
70
+
71
+ u = extra.who
72
+ u.class.should == User
73
+ u.id.should == user.id
74
+
75
+ end
76
+
77
+ end
58
78
  end
@@ -6,6 +6,7 @@ class User
6
6
  def id; 1 end
7
7
  def username=(username); end
8
8
  def username; "steve" end
9
+ def self.find(id); User.new end
9
10
 
10
11
  end
11
12
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steve Klabnik
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- hash: 3599394924060512683
90
+ hash: -4125126624120400925
91
91
  segments:
92
92
  - 0
93
93
  version: "0"