Permalink
Browse files

Add HashOptions module to reduce duplication.

This code was fully duplicated in the configuration classes. The option
specification is the same, so I've moved the code into its own module.
  • Loading branch information...
1 parent 633cac7 commit 90685ca8278e5965f3457d963edd616e2ba6b608 @panthomakos committed Jul 10, 2012
Showing with 23 additions and 22 deletions.
  1. +3 −11 lib/sham/config/assign.rb
  2. +3 −11 lib/sham/config/attributes.rb
  3. +17 −0 lib/sham/config/hash_options.rb
View
@@ -1,9 +1,11 @@
require 'sham/config/base'
-require 'sham/util'
+require 'sham/config/hash_options'
module Sham
class Config
class Assign < Base
+ include HashOptions
+
def initialize(config)
@config = config
end
@@ -22,16 +24,6 @@ def sham(build = false)
object
end
- def options(*args)
- @options = ::Sham::Util.extract_options!(args)
-
- @config.call.each do |key, value|
- @options[key] = parse!(value) unless @options.has_key?(key)
- end
-
- self
- end
-
def args
[]
end
@@ -1,23 +1,15 @@
require 'sham/config/base'
-require 'sham/util'
+require 'sham/config/hash_options'
module Sham
class Config
class Attributes < Base
+ include HashOptions
+
def initialize(config)
@config = config
end
- def options(*args)
- @options = ::Sham::Util.extract_options!(args)
-
- @config.call.each do |key, value|
- @options[key] = parse!(value) unless @options.has_key?(key)
- end
-
- self
- end
-
def args
[@options]
end
@@ -0,0 +1,17 @@
+require 'sham/util'
+
+module Sham
+ class Config
+ module HashOptions
+ def options(*args)
+ @options = ::Sham::Util.extract_options!(args)
+
+ @config.call.each do |key, value|
+ @options[key] = parse!(value) unless @options.has_key?(key)
+ end
+
+ self
+ end
+ end
+ end
+end

0 comments on commit 90685ca

Please sign in to comment.