lib/usecasing_validations/target.rb in usecasing_validations-0.5.3 vs lib/usecasing_validations/target.rb in usecasing_validations-0.5.4
- old
+ new
@@ -1,44 +1,46 @@
module UseCaseValidations
-
+
module Target
def self.included(base)
base.extend(ClassMethods)
end
- def target_sym
- self.class.target_sym
- end
-
- def parent_target_sym
+ def parent_target_name
self.class.options.key?(:in) ? self.class.options[:in] : nil
end
def target
- send(target_sym)
+ send(self.class.target_name)
end
def parent_target
- parent_target_sym ? send(parent_target_sym) : nil
+ parent_target_name ? send(parent_target_name) : nil
end
module ClassMethods
- attr_reader :target_sym, :options
-
- def target(target_sym, options = {})
- @target_sym, @options = target_sym, options
+ def target_name
+ Helpers._get_instance_variable(self, :target_name, nil)
+ end
+ def options
+ Helpers._get_instance_variable(self, :options, {})
+ end
+
+ def target(target_name, options = {})
+ @target_name, @options = target_name, options
+
if options.key?(:in)
define_method(options[:in]) { context.send(options[:in]) }
- define_method(target_sym) { send(options[:in]).send(target_sym) }
+ define_method(target_name) { send(options[:in]).send(target_name) }
else
- define_method(target_sym) { context.send(target_sym) }
+ define_method(target_name) { context.send(target_name) }
end
end
end
-
+
end
end