Sha256: 9c56b34a3a5854805c65eaa4f9268af1acc42839ebe9911b141b443d971155fc

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

module Avo
  module Concerns
    module HandlesFieldArgs
      extend ActiveSupport::Concern

      private

      # Add an instance variable from args
      # That may be a string, boolean, or array
      # Each args should also have a default value
      def add_prop_from_args(args = {}, name: nil, type: :string, default: nil)
        value = default

        if type == :boolean
          value = args[name.to_sym] == true
        else
          value = args[name.to_sym] unless args.dig(name.to_sym).nil?
        end

        instance_variable_set(:"@#{name}", value)
      end

      def add_boolean_prop(args, name, default = false)
        add_prop_from_args args, name: name, default: default, type: :boolean
      end

      def add_array_prop(args, name, default = [])
        add_prop_from_args args, name: name, default: default, type: :array
      end

      def add_string_prop(args, name, default = [])
        add_prop_from_args args, name: name, default: default, type: :string
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
avo-2.10.2 lib/avo/concerns/handles_field_args.rb
avo-2.10.0 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre7 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre6 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre5 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre4 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre2 lib/avo/concerns/handles_field_args.rb
avo-2.9.1.pre1 lib/avo/concerns/handles_field_args.rb
avo-2.9.0 lib/avo/concerns/handles_field_args.rb
avo-2.8.0 lib/avo/concerns/handles_field_args.rb
avo-2.7.1.pre.1 lib/avo/concerns/handles_field_args.rb
avo-2.7.0 lib/avo/concerns/handles_field_args.rb
avo-2.6.1.pre.2 lib/avo/concerns/handles_field_args.rb
avo-2.6.1.pre.1 lib/avo/concerns/handles_field_args.rb
avo-2.6.0 lib/avo/concerns/handles_field_args.rb
avo-2.5.2.pre.7 lib/avo/concerns/handles_field_args.rb
avo-2.5.2.pre.2 lib/avo/concerns/handles_field_args.rb