Sha256: 5a792316499b51399d458789e18fdd6a8b59810448606492705eb559dbfa4198

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

module AngularSprinkles
  class FormBinder
    class Base
      def initialize(_args)
        @method = _args.fetch(:method)
        @args = _args.fetch(:args).dup

        object = _args.fetch(:object)
        attribute = @args.first.to_sym

        @attribute_binding = object.bind(attribute)
      end

      def call
        # Let the original form helper raise the exception
        return @args if helper_is_going_raise_argument_error?

        args_with_binding
      end

      private

      def args_with_binding; raise NotImplementedError; end

      def helper_is_going_raise_argument_error?
        @args.count < required_parameters.count
      end

      def required_parameters
        @method.parameters.select { |i| i.first == :req }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
angular_sprinkles-0.2.0 lib/angular_sprinkles/form_binder/base.rb