Sha256: 08efa717098867e37d3bc04e7ac89615e7bd96bebfdc2ed8a5a957e492847169

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module FmRest
  module Spyke
    module Model
      module GlobalFields
        extend ::ActiveSupport::Concern

        FULLY_QUALIFIED_FIELD_NAME_MATCHER = /\A[^:]+::[^:]+\Z/.freeze

        class_methods do
          def set_globals(values_hash)
            connection.patch(FmRest::V1.globals_path, {
              globalFields: normalize_globals_hash(values_hash)
            })
          end

          private

          def normalize_globals_hash(hash)
            hash.each_with_object({}) do |(k, v), normalized|
              if v.kind_of?(Hash)
                v.each do |k2, v2|
                  normalized["#{k}::#{k2}"] = v2
                end
                next
              end

              unless FULLY_QUALIFIED_FIELD_NAME_MATCHER === k.to_s
                raise ArgumentError, "global fields must be given in fully qualified format (table name::field name)"
              end

              normalized[k] = v
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
fmrest-spyke-0.17.1 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.17.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.17.0.rc1 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.16.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.15.2 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.15.1 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.15.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.14.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.13.1 lib/fmrest/spyke/model/global_fields.rb
fmrest-spyke-0.13.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.12.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.11.1 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.11.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.10.1 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.10.0 lib/fmrest/spyke/model/global_fields.rb
fmrest-0.9.0 lib/fmrest/spyke/model/global_fields.rb