Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of converted Rails (AR) plugin to DM. (which was mostl…
…y a great joy)
- Loading branch information
0 parents
commit d413bc3
Showing
15 changed files
with
845 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## OS STUFF | ||
.DS_Store | ||
|
||
## TM SPECIFIC | ||
*.tmproj | ||
tmtags | ||
|
||
## PROJECT::GENERAL | ||
*.sw? | ||
coverage | ||
rdoc | ||
pkg | ||
|
||
## PROJECT::SPECIFIC | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
=== 0.0.1 / 2009-07-11 | ||
|
||
* Release! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2009 Kematzy [kematzy gmail com] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
History.txt | ||
LICENSE | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
TODO | ||
lib/dm-is-published.rb | ||
lib/dm-is-published/is/published.rb | ||
lib/dm-is-published/is/version.rb | ||
spec/integration/published_spec.rb | ||
spec/spec.opts | ||
spec/spec_helper.rb | ||
tasks/install.rb | ||
tasks/spec.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
= dm-is-published | ||
|
||
This plugin makes it very easy to add different states to your models, like 'draft' vs 'live'. | ||
By default it also adds validations of the field value. | ||
|
||
Originally inspired by the Rails plugin +acts_as_publishable+ by <b>fr.ivolo.us</b>. | ||
|
||
|
||
== Installation | ||
|
||
# Add GitHub to your RubyGems sources | ||
$ gem sources -a http://gems.github.com | ||
|
||
$ (sudo)? gem install kematzy-dm-is-published | ||
|
||
<b>NB! Depends upon the whole DataMapper suite being installed, and has ONLY been tested with DM 0.10.0 (next branch).</b> | ||
|
||
|
||
== Getting Started | ||
|
||
First of all, for a better understanding of this gem, make sure you study | ||
the '<tt>dm-is-published/spec/integration/published_spec.rb</tt>' file. | ||
|
||
---- | ||
|
||
Require +dm-is-published+ in your app. | ||
|
||
require 'dm-core' # must be required first | ||
require 'dm-is-published' | ||
|
||
Lets say we have an Article class, and each Article can have a current state, | ||
ie: whether it's Live, Draft or an Obituary awaiting the death of someone famous (real or rumored) | ||
|
||
|
||
class Article | ||
include DataMapper::Resource | ||
property :id, Serial | ||
property :title, String | ||
...<snip> | ||
|
||
is :published | ||
|
||
end | ||
|
||
Once you have your Article model we can create our Articles just as normal | ||
|
||
Article.create(:title => 'Example 1') | ||
|
||
|
||
The instance of <tt>Article.get(1)</tt> now has the following things for free: | ||
|
||
* a <tt>:publish_status</tt> attribute with the value <tt>'live'</tt>. Default choices are <tt>[ :live, :draft, :hidden ]</tt>. | ||
|
||
* <tt>:is_live?, :is_draft? or :is_hidden?</tt> methods that returns true/false based upon the state. | ||
|
||
* <tt>:save_as_live</tt>, <tt>:save_as_draft</tt> or <tt>:save_as_hidden</tt> converts the instance to the state and saves it. | ||
|
||
* <tt>:publishable?</tt> method that returns true for models where <tt>is :published </tt> has been declared, | ||
but <b>false</b> for those where it has not been declared. | ||
|
||
|
||
The Article class also gets a bit of new functionality: | ||
|
||
Article.all(:draft) => finds all Articles with :publish_status = :draft | ||
|
||
|
||
Article.all(:draft, :author => @author_joe ) => finds all Articles with :publish_status = :draft and author == Joe | ||
|
||
|
||
|
||
Todo Need to write more documentation here.. | ||
|
||
|
||
== Usage Scenarios | ||
|
||
In a Blog/Publishing scenario you could use it like this: | ||
|
||
class Article | ||
...<snip>... | ||
|
||
is :published :live, :draft, :hidden | ||
|
||
end | ||
|
||
Whereas in another scenario - like in a MenuItem model for a Restaurant - you could use it like this: | ||
|
||
class MenuItem | ||
...<snip>... | ||
|
||
is :published :on, :off # the item is either on the menu or not | ||
|
||
end | ||
|
||
|
||
== RTFM | ||
|
||
As I said above, for a better understanding of this gem/plugin, make sure you study the '<tt>dm-is-published/spec/integration/published_spec.rb</tt>' file. | ||
|
||
|
||
== Errors / Bugs | ||
|
||
If something is not behaving intuitively, it is a bug, and should be reported. | ||
Report it here: http://datamapper.lighthouseapp.com/ | ||
|
||
=== Credits | ||
|
||
Copyright (c) 2008-05-07 [Kematzy at gmail] | ||
|
||
Loosely based on the ActsAsPublishable plugin by [http://fr.ivolo.us/posts/acts-as-publishable] | ||
|
||
== Licence | ||
|
||
Released under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'pathname' | ||
require 'rubygems' | ||
require 'hoe' | ||
|
||
ROOT = Pathname(__FILE__).dirname.expand_path | ||
JRUBY = RUBY_PLATFORM =~ /java/ | ||
WINDOWS = Gem.win_platform? | ||
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS']) | ||
|
||
require ROOT + 'lib/dm-is-published/is/version' | ||
|
||
# define some constants to help with task files | ||
GEM_NAME = 'dm-is-published' | ||
GEM_VERSION = DataMapper::Is::Published::VERSION | ||
|
||
Hoe.new(GEM_NAME, GEM_VERSION) do |p| | ||
p.developer('Kematzy', 'kematzy gmail com') | ||
|
||
p.description = 'A DataMapper plugin provides an easy way to add different states to your models.' | ||
p.summary = 'A DataMapper plugin provides an easy way to add different states to your models.' | ||
p.url = 'http://github.com/kematzy/dm-is-published' | ||
|
||
p.clean_globs |= %w[ log pkg coverage ] | ||
p.spec_extras = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] } | ||
|
||
p.extra_deps << ['dm-core', "~> DMGen::DM_VERSION"] | ||
|
||
end | ||
|
||
Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Needed to import datamapper and other gems | ||
require 'rubygems' | ||
require 'pathname' | ||
|
||
# Add all external dependencies for the plugin here | ||
gem 'dm-core', '~> 0.10.0' | ||
require 'dm-core' | ||
gem 'dm-validations', '~> 0.10.0' | ||
require 'dm-validations' | ||
|
||
# Require plugin-files | ||
require Pathname(__FILE__).dirname.expand_path / 'dm-is-published' / 'is' / 'published.rb' | ||
|
||
DataMapper::Model.append_extensions(DataMapper::Is::Published) | ||
DataMapper::Model.append_inclusions(DataMapper::Is::Published::ResourceInstanceMethods) |
Oops, something went wrong.