lib/spaced.rb in spaced-0.3.1 vs lib/spaced.rb in spaced-0.4.0
- old
+ new
@@ -12,11 +12,11 @@
attr_reader :parent
end
module ClassMethods
- def namespace(name, klass = nil, &)
+ def namespace(name, klass = nil, &) # rubocop:disable Metrics/*
if klass
raise "#{klass} must be a subclass of Spaced::Base" unless klass < Spaced::Base
else
class_name = name.to_s.split("_").collect(&:capitalize).join
klass = module_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -38,24 +38,44 @@
end
# Define the bang and predicate methods.
methods = klass.instance_methods(false)
- if methods.include?(:call)
+ if methods.include?(:_!)
module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{name}!(...); #{name}._!(...); end # def user!; user._!; end
+ RUBY
+ elsif methods.include?(:"#{name}!")
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{name}!(...); #{name}.#{name}!(...); end # def user!; user.user!; end
+ RUBY
+ elsif methods.include?(:call) # DEPRECATED
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}!(...); #{name}.call(...); end # def user!(...); user.call(...); end
RUBY
else
define_method :"#{name}!" do
- raise NoMethodError, "undefined method `#{name}!' for #<#{klass}>. Have you defined `#{klass}#call`?", caller
+ raise NoMethodError,
+ "undefined method `#{name}!' for #<#{klass}>. Have you defined `#{klass}#_!`?", caller
end
end
- if methods.include?(:predicate)
- define_method(:"#{name}?") { send(name).predicate }
+ if methods.include?(:_?)
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{name}?; #{name}._?; end # def user?; user._?; end
+ RUBY
+ elsif methods.include?(:"#{name}?")
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{name}?; #{name}.#{name}?; end # def user?; user.user?; end
+ RUBY
+ elsif methods.include?(:predicate) # DEPRECATED
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{name}?; #{name}.predicate; end # def user?; user.predicate; end
+ RUBY
else
define_method :"#{name}?" do
- raise NoMethodError, "undefined method `#{name}?' for #<#{klass}>. Have you defined `#{klass}#predicate`?",
+ raise NoMethodError,
+ "undefined method `#{name}?' for #<#{klass}>. Have you defined `#{klass}#_?`?",
caller
end
end
end
end