Module: DataMapper::Is::Remixable
- Included in:
- Model
- Defined in:
- lib/dm-is-remixable/is/remixable.rb
Defined Under Namespace
Modules: RemixeeClassMethods, RemixeeInstanceMethods, RemixerClassMethods, RemixerInstanceMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Adds remixer methods to DataMapper::Resource.
Instance Method Summary collapse
-
#is_remixable(options = {}) ⇒ Object
-
is_remixable ==== Description Adds RemixeeClassMethods and RemixeeInstanceMethods to any model that is: remixable ==== Examples class User #Remixer remixes Commentable remixes Vote end.
-
Class Method Details
.included(base) ⇒ Object
Adds remixer methods to DataMapper::Resource
16 17 18 19 |
# File 'lib/dm-is-remixable/is/remixable.rb', line 16 def self.included(base) base.send(:include,RemixerClassMethods) base.send(:include,RemixerInstanceMethods) end |
Instance Method Details
#is_remixable(options = {}) ⇒ Object
-
is_remixable
Description
Adds RemixeeClassMethods and RemixeeInstanceMethods to any model that is: remixable
Examples
class User #Remixer
remixes Commentable
remixes Vote
end
module Commentable #Remixable
include DataMapper::Resource
is :remixable,
:suffix => "comment"
end
module Vote #Remixable
include DataMapper::Resource
is :remixable
Notes
These options are just available for whatever reason your Remixable Module name
might not be what you'd like to see the table name and property accessor named.
These are just configurable defaults, upon remixing the class_name and accessor there
take precedence over the defaults set here
Options
:suffix <String>
Table suffix, defaults to YourModule.name.downcase.singular
Yields table name of remixer_suffix; ie user_comments, user_votes
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dm-is-remixable/is/remixable.rb', line 51 def is_remixable(={}) extend DataMapper::Is::Remixable::RemixeeClassMethods include DataMapper::Is::Remixable::RemixeeInstanceMethods @is_remixable = true # support clean suffixes for nested modules inflector = DataMapper::Inflector default_suffix = inflector.demodulize(self.name) default_suffix = inflector.singularize(default_suffix) default_suffix = inflector.underscore(default_suffix) suffix(.delete(:suffix) || default_suffix) end |