Skip to content
Browse files

Added predefine!.

  • Loading branch information...
1 parent 424b2b6 commit f5cad407c0aacb16067114b07e919744a91867be @postmodern committed
Showing with 20 additions and 12 deletions.
  1. +20 −12 lib/dm-is-predefined/is/predefined.rb
View
32 lib/dm-is-predefined/is/predefined.rb
@@ -38,12 +38,7 @@ module MigrationMethods
def auto_migrate!(repository_name=self.repository_name)
result = super(repository_name)
- DataMapper.repository(repository_name) do
- predefined_attributes.each_value do |attributes|
- create(attributes)
- end
- end
-
+ predefine!(repository_name)
return result
end
@@ -61,12 +56,7 @@ def auto_migrate!(repository_name=self.repository_name)
def auto_upgrade!(repository_name=self.repository_name)
result = super(repository_name)
- DataMapper.repository(repository_name) do
- predefined_attributes.each_value do |attributes|
- first_or_create(attributes)
- end
- end
-
+ predefine!(repository_name)
return result
end
end
@@ -198,6 +188,24 @@ def predefined_resource_with(query={})
raise(UnknownResource,"Could not find a predefined resource which shared the given attributes")
end
+ #
+ # Creates the predefined resources.
+ #
+ # @param [Symbol] repository_name
+ # The repository to perform the upgrade within.
+ #
+ # @since 0.4.0
+ #
+ # @api public
+ #
+ def predefine!(repository_name=self.repository_name)
+ DataMapper.repository(repository_name) do
+ predefined_attributes.each_value do |attributes|
+ first_or_create(attributes)
+ end
+ end
+ end
+
protected
#

0 comments on commit f5cad40

Please sign in to comment.
Something went wrong with that request. Please try again.