Sha256: 35f6b5b76431e40f4596064495ef14a2b4e44c5ada2fb1f91ffd28d188f11c0f

Contents?: true

Size: 634 Bytes

Versions: 2

Compression:

Stored size: 634 Bytes

Contents

module SonJay
  module ActsAsModel

    def self.included(other)
      other.extend ClassBehavior
    end

    # Deprecated
    def sonj_content
      model_content
    end

    def to_s
      to_json
    end

    def inspect
      "#<#{self.class.name} #{to_json}>"
    end

    module ClassBehavior

      def parse_json(json)
        data = JSON.parse( json )
        instance = new
        instance.model_content.load_data data
        instance
      end

      def array_class
        @array_class ||= begin
          klass = SonJay::ModelArray( self )
          const_set :Array, klass
        end
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
son_jay-0.5.2 lib/son_jay/acts_as_model.rb
son_jay-0.5.1 lib/son_jay/acts_as_model.rb