acts_as_publishable 0.1.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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/acts_as_publishable.rb
4
+ lib/acts_as_publishable/acts_as_publishable.rb
5
+ Manifest
@@ -0,0 +1,41 @@
1
+ = acts_as_publishable
2
+
3
+ Rails gem for making ActiveRecord models publishable.
4
+
5
+ == Installation
6
+
7
+ gem install acts_as_publishable
8
+
9
+ == Usage
10
+
11
+ Make a model publishable:
12
+
13
+ class MyModel < ActiveRecord::Base
14
+ acts_as_publishable
15
+
16
+ ...
17
+ end
18
+
19
+ Create a migration that adds the needed columns to the my_models table:
20
+
21
+ script/generate migration AddPublishableColumnsToMyModel publish_now:boolean published_from:datetime published_to:datetime
22
+
23
+ Now you can ask if an instance of MyModel is published:
24
+
25
+ my_model = MyModel.first
26
+ my_model.published?
27
+ => true
28
+
29
+ The published? method returns true if my_model either has publish_now set to true or published_from is set in the past and published_to is set in the future.
30
+
31
+ And you can also find instances of MyModel that are published:
32
+
33
+ MyModel.find_published
34
+
35
+ This finds all instances where published? returns true.
36
+
37
+ The find_published finder method accepts any of the normal options as the default find method accepts.
38
+
39
+ == License
40
+
41
+ acts_as_publishable is distributed under the Simplified BSD License, copyright (c) 2010 Rasmus Bang Grouleff
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('acts_as_publishable', '0.1.0') do |p|
6
+ p.description = "Makes Active Record models publishable"
7
+ p.url = "http://github.com/rbgrouleff/acts_as_publishable"
8
+ p.author = "Rasmus Bang Grouleff"
9
+ p.email = "rasmus@anybite.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{acts_as_publishable}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rasmus Bang Grouleff"]
9
+ s.date = %q{2010-06-12}
10
+ s.description = %q{Makes Active Record models publishable}
11
+ s.email = %q{rasmus@anybite.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/acts_as_publishable.rb", "lib/acts_as_publishable/acts_as_publishable.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/acts_as_publishable.rb", "lib/acts_as_publishable/acts_as_publishable.rb", "Manifest", "acts_as_publishable.gemspec"]
14
+ s.homepage = %q{http://github.com/rbgrouleff/acts_as_publishable}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_as_publishable", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{acts_as_publishable}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Makes Active Record models publishable}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ require 'acts_as_publishable/acts_as_publishable'
2
+
3
+ ActiveRecord::Base.send :include, ActsAsPublishable
@@ -0,0 +1,42 @@
1
+ module ActsAsPublishable
2
+ def self.included(base)
3
+ base.extend ActsAsPublishable::ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def acts_as_publishable(options = {})
8
+ metaclass = (class << self; self; end)
9
+
10
+ return if metaclass.included_modules.include?(ActsAsPublishable::SingletonMethods)
11
+
12
+ send :extend, ActsAsPublishable::SingletonMethods
13
+
14
+ cattr_accessor :publish_now_column, :published_from_column, :published_to_column, :default_published_now
15
+
16
+ self.publish_now_column = options[:publish_now_column] || 'publish_now'
17
+ self.published_from_column = options[:published_from_column] || 'published_from'
18
+ self.published_to_column = options[:published_to_column] || 'published_to'
19
+ self.default_published_now = options[:default_published_now]
20
+
21
+ send :include, ActsAsPublishable::InstanceMethods
22
+ end
23
+
24
+
25
+ end
26
+
27
+ module SingletonMethods
28
+ def find_published(options = {})
29
+ scope = scoped(:conditions => ["#{publish_now_column} = :published OR (#{published_from_column} <= :published_from AND #{published_to_column} >= :published_to)", {:published => true, :published_from => Time.now, :published_to => Time.now}])
30
+ scope.find(:all, options)
31
+ end
32
+ end
33
+
34
+ module InstanceMethods
35
+ def published?
36
+ now = Time.now
37
+ @from ||= self[self.class.published_from_column.to_sym]
38
+ @to ||= self[self.class.published_to_column.to_sym]
39
+ self[self.class.publish_now_column.to_sym] || ((@from && @from <= now) && (@to && @to >= now))
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_publishable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Rasmus Bang Grouleff
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-12 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Makes Active Record models publishable
23
+ email: rasmus@anybite.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - lib/acts_as_publishable.rb
31
+ - lib/acts_as_publishable/acts_as_publishable.rb
32
+ files:
33
+ - README.rdoc
34
+ - Rakefile
35
+ - lib/acts_as_publishable.rb
36
+ - lib/acts_as_publishable/acts_as_publishable.rb
37
+ - Manifest
38
+ - acts_as_publishable.gemspec
39
+ has_rdoc: true
40
+ homepage: http://github.com/rbgrouleff/acts_as_publishable
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --line-numbers
46
+ - --inline-source
47
+ - --title
48
+ - Acts_as_publishable
49
+ - --main
50
+ - README.rdoc
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 11
68
+ segments:
69
+ - 1
70
+ - 2
71
+ version: "1.2"
72
+ requirements: []
73
+
74
+ rubyforge_project: acts_as_publishable
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Makes Active Record models publishable
79
+ test_files: []
80
+