publishable 0.1.2 → 0.1.3

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.
@@ -0,0 +1,35 @@
1
+ h1. Publishable
2
+
3
+ <pre>
4
+ gem install publishable
5
+ </pre>
6
+
7
+ h2. Setup
8
+
9
+ you need a datetime column in your table and call publishable in your class body
10
+
11
+ <pre>
12
+ class Model < ActiveRecord::Base
13
+ publishable
14
+
15
+ # OR
16
+
17
+ publishable :made_public_on # if your column is not named published_at
18
+ end
19
+ </pre>
20
+
21
+ h2. Methods
22
+
23
+ <pre>
24
+ album = Album.new
25
+
26
+ album.published? # => false
27
+ album.publish!
28
+ album.published? # => true
29
+
30
+ Album.published.all # => finds all published albums
31
+ </pre>
32
+
33
+ please see specs for details
34
+
35
+ Copyright (c) 2009 Martin Linkhorst, released under the MIT license.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -10,22 +10,26 @@ module Publishable
10
10
 
11
11
  named_scope :published, lambda { |*args|
12
12
  if args.first.nil? || TRUE_VALUES.include?(args.first)
13
- { :conditions => ["#{quoted_table_name}.#{publishable_column} IS NOT NULL AND #{quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(publishable_column)} <= ?", Time.now.utc] }
13
+ { :conditions => ["#{quoted_table_name}.#{quoted_publishable_column_name} IS NOT NULL AND #{quoted_table_name}.#{quoted_publishable_column_name} <= ?", Time.now.utc] }
14
14
  else
15
- { :conditions => ["#{quoted_table_name}.#{publishable_column} IS NULL OR #{quoted_table_name}.#{ActiveRecord::Base.connection.quote_column_name(publishable_column)} > ?", Time.now.utc] }
15
+ { :conditions => ["#{quoted_table_name}.#{quoted_publishable_column_name} IS NULL OR #{quoted_table_name}.#{quoted_publishable_column_name} > ?", Time.now.utc] }
16
16
  end
17
17
  }
18
18
 
19
19
  class_eval do
20
20
  class << self
21
- attr_accessor :publishable_column
21
+ attr_accessor :publishable_column_name
22
22
 
23
23
  def unpublished
24
24
  published(false)
25
- end
25
+ end
26
+
27
+ def quoted_publishable_column_name
28
+ ActiveRecord::Base.connection.quote_column_name(publishable_column_name)
29
+ end
26
30
  end
27
31
 
28
- self.publishable_column = column
32
+ self.publishable_column_name = column
29
33
 
30
34
  def published?
31
35
  !!published
@@ -36,7 +40,7 @@ module Publishable
36
40
  end
37
41
 
38
42
  def published
39
- send(self.class.publishable_column) && send(self.class.publishable_column) <= Time.now
43
+ send(self.class.publishable_column_name) && send(self.class.publishable_column_name) <= Time.now
40
44
  end
41
45
 
42
46
  def published=(boolean)
@@ -44,11 +48,11 @@ module Publishable
44
48
  end
45
49
 
46
50
  def publish(time = Time.now)
47
- self.send("#{self.class.publishable_column}=", time.utc) unless published?
51
+ self.send("#{self.class.publishable_column_name}=", time.utc) unless published?
48
52
  end
49
53
 
50
54
  def unpublish
51
- self.send("#{self.class.publishable_column}=", nil)
55
+ self.send("#{self.class.publishable_column_name}=", nil)
52
56
  end
53
57
 
54
58
  def publish!
@@ -60,7 +64,7 @@ module Publishable
60
64
 
61
65
  def unpublish!
62
66
  unpublish
63
- update_attribute(self.class.publishable_column, published_at)
67
+ update_attribute(self.class.publishable_column_name, send(publishable_column_name))
64
68
  end
65
69
  end
66
70
  end
@@ -5,21 +5,21 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{publishable}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Linkhorst"]
12
- s.date = %q{2009-12-03}
12
+ s.date = %q{2009-12-11}
13
13
  s.description = %q{Provides methods to publish and unpublish your active record models based on a datetime. Also adds named scopes to nicely filter your records. Does not touch any controller or views.}
14
14
  s.email = %q{m.linkhorst@googlemail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
21
  "LICENSE",
22
- "README",
22
+ "README.textile",
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "db/schema.rb",
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "/spec_helper")
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
2
 
3
3
  class Model < ActiveRecord::Base
4
4
  include Publishable
@@ -21,7 +21,7 @@ describe Publishable do
21
21
 
22
22
  it "should be published? when :published_at is now" do
23
23
  now = Time.now; Time.stubs(:now).returns(now)
24
- @model.published_at = Time.now #stub me
24
+ @model.published_at = Time.now
25
25
  @model.should be_published
26
26
  end
27
27
 
@@ -37,8 +37,8 @@ describe Publishable do
37
37
  @model.should_not be_published
38
38
  end
39
39
 
40
- it "should ask :publishable_column" do
41
- Model.expects(:publishable_column).returns(:published_at)
40
+ it "should ask :publishable_column_name" do
41
+ Model.expects(:publishable_column_name).returns(:published_at)
42
42
  @model.published?
43
43
  end
44
44
  end
@@ -50,13 +50,13 @@ describe Publishable do
50
50
 
51
51
  it "should set :published_at to current time with no parameter" do
52
52
  now = Time.now; Time.expects(:now).returns(now)
53
- @model.expects(:published_at=).with(now).returns(true)
53
+ @model.expects(:published_at=).with(now).returns(now)
54
54
  @model.publish
55
55
  end
56
56
 
57
57
  it "should set :published_at to given time if parameter present" do
58
58
  tomorrow = Time.now + 1.day
59
- @model.expects(:published_at=).with(tomorrow).returns(true)
59
+ @model.expects(:published_at=).with(tomorrow).returns(tomorrow)
60
60
  @model.publish(tomorrow)
61
61
  end
62
62
 
@@ -112,7 +112,7 @@ describe Publishable do
112
112
 
113
113
  describe "database column" do
114
114
  it "should default to :published_at" do
115
- Model.publishable_column.should == :published_at
115
+ Model.publishable_column_name.should == :published_at
116
116
  end
117
117
 
118
118
  it "should be possible to change the column name" do
@@ -120,7 +120,7 @@ describe Publishable do
120
120
  include Publishable
121
121
  publishable :made_available_on
122
122
  end
123
- Model2.publishable_column.should == :made_available_on
123
+ Model2.publishable_column_name.should == :made_available_on
124
124
  end
125
125
  end
126
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Linkhorst
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-03 00:00:00 +10:00
12
+ date: 2009-12-11 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,11 +21,11 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - LICENSE
24
- - README
24
+ - README.textile
25
25
  files:
26
26
  - .gitignore
27
27
  - LICENSE
28
- - README
28
+ - README.textile
29
29
  - Rakefile
30
30
  - VERSION
31
31
  - db/schema.rb
data/README DELETED
File without changes