Permalink
Browse files

DRY some code into DSLMethods

  • Loading branch information...
1 parent 031f47d commit 42aaae243a0971794f19e41b0133cff005a18522 @jhchabran jhchabran committed Jul 21, 2012
Showing with 20 additions and 25 deletions.
  1. +2 −13 lib/vintner/builder.rb
  2. +16 −0 lib/vintner/dsl_methods.rb
  3. +1 −12 lib/vintner/importer.rb
  4. +1 −0 lib/vintner/representation.rb
View
@@ -1,17 +1,6 @@
module Vintner
class Builder
- def initialize &block
- @store = {}
- @block = block
- end
-
- def method_missing method_id, *args, &block
- @store[method_id] = self.class.new(&block)
- end
-
- def property name
- @store[name] = @representer.properties[name.to_sym].export(@model)
- end
+ include DSLMethods
def export representer, model
@representer = representer
@@ -27,7 +16,7 @@ def export representer, model
if builder.is_a? Builder
hash[key] = builder.export(representer, model)
else
- hash[key] = builder
+ hash[key] = builder.export(@model)
end
end
View
@@ -0,0 +1,16 @@
+module Vintner
+ module DSLMethods
+ def initialize &block
+ @store = {}
+ @block = block
+ end
+
+ def method_missing method_id, *args, &block
+ @store[method_id] = self.class.new(&block)
+ end
+
+ def property name
+ @store[name] = @representer.properties[name.to_sym]
+ end
+ end
+end
View
@@ -1,17 +1,6 @@
module Vintner
class Importer
- def initialize &block
- @store = {}
- @block = block
- end
-
- def method_missing method_id, *args, &block
- @store[method_id] = self.class.new(&block)
- end
-
- def property name
- @store[name] = @representer.properties[name.to_sym]
- end
+ include DSLMethods
def import representer, model, hash
@representer = representer
@@ -1,3 +1,4 @@
+require 'vintner/dsl_methods'
require 'vintner/builder'
require 'vintner/importer'

0 comments on commit 42aaae2

Please sign in to comment.