lib/the_help/service.rb in the_help-1.0.2 vs lib/the_help/service.rb in the_help-1.1.0

- old
+ new

@@ -60,10 +60,11 @@ # end # # CreateNewUserAccount.(context: current_user, user: new_user_object) class Service include ProvidesCallbacks + include ServiceCaller # The default :not_authorized callback # # It will raise a TheHelp::NotAuthorizedError when the context is not # authorized to perform the service. @@ -71,10 +72,20 @@ raise NotAuthorizedError, "Not authorized to access #{service.name} as #{context.inspect}." } class << self + # Defines attr_accessors with scoping options + def attr_accessor(*names, make_private: false, private_reader: false, + private_writer: false) + super(*names) + names.each do |name| + private name if make_private || private_reader + private "#{name}=" if make_private || private_writer + end + end + # Convenience method to instantiate the service and immediately call it # # Any arguments are passed to #initialize # # @return [Class] Returns the receiver @@ -122,19 +133,18 @@ private :authorized? self end def input(name, **options) - attr_accessor name + attr_accessor name, make_private: true if options.key?(:default) required_inputs.delete(name) define_method(name) do instance_variable_get("@#{name}") || options[:default] end else required_inputs << name end - private name, "#{name}=" self end end def initialize(context:, logger: Logger.new($stdout),