Sha256: 15ee01d274e5e09be738793f84c71add07418a6ef58d00792fff7330835bdbeb

Contents?: true

Size: 1.37 KB

Versions: 29

Compression:

Stored size: 1.37 KB

Contents

module NetSuite
  module Support
    module Fields
      include Attributes

      def self.included(base)
        base.send(:extend, ClassMethods)
      end

      module ClassMethods

        def fields(*args)
          if args.empty?
             @fields ||= Set.new
          else
            args.each do |arg|
              field arg
            end
          end
        end

        def field(name, klass = nil)
          name_sym = name.to_sym
          fields << name_sym
          if klass
            define_method(name_sym) do
              attributes[name_sym] ||= klass.new
            end

            define_method("#{name_sym}=") do |value|
              attributes[name_sym] = value.kind_of?(klass) ? value : klass.new(value)
            end
          else
            define_method(name_sym) do
              attributes[name_sym]
            end

            define_method("#{name_sym}=") do |value|
              attributes[name_sym] = value
            end
          end
        end

        def read_only_fields(*args)
          if args.empty?
             @read_only_fields ||= Set.new
          else
            args.each do |arg|
              read_only_field arg
            end
          end
        end

        def read_only_field(name)
          name_sym = name.to_sym
          read_only_fields << name_sym
          field name
        end

      end

    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
netsuite-0.0.49 lib/netsuite/support/fields.rb
netsuite-0.0.48 lib/netsuite/support/fields.rb
netsuite-0.0.47 lib/netsuite/support/fields.rb
netsuite-0.0.45 lib/netsuite/support/fields.rb
netsuite-0.0.44 lib/netsuite/support/fields.rb
netsuite-0.0.43 lib/netsuite/support/fields.rb
netsuite-0.0.42 lib/netsuite/support/fields.rb
netsuite-0.0.41 lib/netsuite/support/fields.rb
netsuite-0.0.40 lib/netsuite/support/fields.rb
netsuite-0.0.39 lib/netsuite/support/fields.rb
netsuite-0.0.38 lib/netsuite/support/fields.rb
netsuite-0.0.37 lib/netsuite/support/fields.rb
netsuite-0.0.36 lib/netsuite/support/fields.rb
netsuite-0.0.35 lib/netsuite/support/fields.rb
netsuite-0.0.34 lib/netsuite/support/fields.rb
netsuite-0.0.33 lib/netsuite/support/fields.rb
netsuite-0.0.32 lib/netsuite/support/fields.rb
netsuite-0.0.31 lib/netsuite/support/fields.rb
netsuite-0.0.30 lib/netsuite/support/fields.rb
netsuite-0.0.29 lib/netsuite/support/fields.rb