is_publishable 0.0.2 → 0.0.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.
data/README.md CHANGED
@@ -42,13 +42,16 @@ After this, simply add `publishable` to your model (be sure to add published and
42
42
  publishable
43
43
  end
44
44
 
45
- The following scopes are now available:
45
+ After this, when you first mark an Article as published and published_at is not set, published_at will automatically be set to now. If published_at is already set, it will not be changed.
46
+
47
+ ### Scopes
46
48
 
47
49
  * published -- returns all Article that published=true and published_at is a date in the past
48
50
  * unpublished -- returns all Articles that are published=false or published=true and published_at is a date in the future
49
51
 
50
52
 
51
- The follow instance methods are now available:
53
+ ### Instance Methods
54
+
52
55
  * published? -- returns true if published=true and published_at is a date in the past
53
56
  * unpublished? -- returns true if published=false or published=true and published_at is a date in the future
54
57
 
@@ -1,3 +1,3 @@
1
1
  module IsPublishable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -18,7 +18,8 @@ module IsPublishable
18
18
  # create before_save hook
19
19
  before_save do
20
20
  if published and published_at.nil?
21
- self.published_at = Time.zone.now
21
+ # when not set, set time to now (minus 1 second for easy test integration)
22
+ self.published_at = Time.zone.now - 1.second
22
23
  elsif published.nil?
23
24
  self.published = false
24
25
  end
@@ -35,6 +36,16 @@ module IsPublishable
35
36
 
36
37
  module InstanceMethods
37
38
 
39
+ def publish!
40
+ self.published = true
41
+ save
42
+ end
43
+
44
+ def unpublish!
45
+ self.published = false
46
+ save
47
+ end
48
+
38
49
  def published?(time = Time.zone.now)
39
50
  published and published_at.present? and published_at < time
40
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_publishable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec