Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract external builders out into integrations file.

  • Loading branch information...
commit 528704ea934c812f1f6c1578527cf8ae8bf6293e 1 parent 1c0ebd3
@cmeiklejohn authored
View
2  lib/watchmaker.rb
@@ -2,10 +2,12 @@
require "watchmaker/version"
require "watchmaker/configuration"
+require "watchmaker/integrations"
require "watchmaker/learner"
require "watchmaker/constructor"
module Watchmaker # :nodoc:
include Learner
include Constructor
+ include Integrations
end
View
20 lib/watchmaker/constructor.rb
@@ -6,18 +6,6 @@ module Constructor
module ClassMethods
- # Construct from a factory.
- #
- def construct_from_factory(factory)
- Factory.create(factory.to_sym)
- end
-
- # Construct from another watchmaker.
- #
- def construct_from_watchmaker(watchmaker)
- construct(watchmaker.to_sym)
- end
-
# Contruct a profile.
#
def construct(profile)
@@ -37,9 +25,9 @@ def construct(profile)
if abstracts = dependencies[:abstract]
abstracts.each do |abstract|
if Configuration.learned?(abstract)
- objects << construct_from_watchmaker(abstract)
+ objects << from_watchmaker(abstract)
else
- objects << construct_from_factory(abstract)
+ objects << from_factory(abstract)
end
end
end
@@ -48,7 +36,7 @@ def construct(profile)
#
if factories = dependencies[:factories]
factories.each do |factory|
- objects << construct_from_factory(factory)
+ objects << from_factory(factory)
end
end
@@ -56,7 +44,7 @@ def construct(profile)
#
if watchmakers = dependencies[:watchmakers]
watchmakers.each do |watchmaker|
- objects << construct_from_watchmaker(watchmaker)
+ objects << from_watchmaker(watchmaker)
end
end
View
23 lib/watchmaker/integrations.rb
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+
+module Watchmaker
+ module Integrations
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+
+ # Construct from a factory.
+ #
+ def from_factory(factory, method = :create)
+ Factory.send(method, factory.to_sym)
+ end
+
+ # Construct from another watchmaker.
+ #
+ def from_watchmaker(watchmaker, method = :construct)
+ self.send(method, watchmaker.to_sym)
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.