summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/ayk/options.rb42
-rw-r--r--spec/options.rb4
2 files changed, 24 insertions, 22 deletions
diff --git a/lib/ayk/options.rb b/lib/ayk/options.rb
index 5650609..5b34481 100644
--- a/lib/ayk/options.rb
+++ b/lib/ayk/options.rb
@@ -32,6 +32,8 @@ module AYK
yield(self) if block_given?
end
#
+ attr_reader :name
+ #
# Shortcut for instance_eval
def dsl &block
instance_eval(&block) if block
@@ -142,26 +144,22 @@ module AYK
def pretty_print q; q.pp_hash @hash end
end
#
-# # extend your class with this
-# module Optioned
-# def self.included(into)
-# into.extend(SingletonMethods)
-#
-# snaked = into.name.split('::').last
-# snaked = snaked.gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
-#
-# options = Innate.options.sub(snaked)
-# into.instance_variable_set(:@options, options)
-# end
-#
-# module SingletonMethods
-# attr_reader :options
-# end
-#
-# private
-#
-# def options
-# self.class.options
-# end
-# end
+ # extend your class with this
+ module Optioned
+ def self.included(into)
+ into.extend(SingletonMethods)
+ snaked = into.name.split('::').last
+ snaked = snaked.gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
+ into.instance_variable_set :@options, Options.new(snaked)
+ end
+ #
+ module SingletonMethods
+ attr_reader :options
+ end
+ #
+ private
+ def options
+ self.class.options
+ end
+ end
end
diff --git a/spec/options.rb b/spec/options.rb
index 25741db..0fd84d5 100644
--- a/spec/options.rb
+++ b/spec/options.rb
@@ -81,6 +81,10 @@ describe AYK::Options do
end
opts.var.should eql 666
end
+ it "should be nicely included" do
+ class A__A; include AYK::Optioned end
+ A__A.options.name.should eql 'a__a'
+ end
end
#
end