Sha256: 801d17ff31452a148853a7ac9f26dcdca0cb7b4a0950cc6150f9b6cc73592efb

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

# frozen_string_literal: true

module DynamicScaffold
  module JSONObject
    module Attribute
      extend ActiveSupport::Concern

      included do
        @json_object_attribute_names ||= []

        define_method :valid? do |context = nil|
          result = super(context)
          json_object_attribute_names = self.class.instance_variable_get(:@json_object_attribute_names)
          json_object_attribute_names.all? {|method| public_send(method).valid?(context) } && result
        end
      end

      module ClassMethods
        def json_object_attributte(attribute_name, model)
          @json_object_attribute_names << attribute_name
          serialize attribute_name, model
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamic_scaffold-2.0.1 lib/dynamic_scaffold/json_object/attribute.rb
dynamic_scaffold-2.0.0 lib/dynamic_scaffold/json_object/attribute.rb