Sha256: a393a79409570029997d63a1764169af1e105c1e59de3ef2f5b51a5b8b265f44

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

module Locomotive::Steam
  module Models
    module Entity

      include Locomotive::Steam::Models::Concerns::Validation
      include Locomotive::Steam::Models::Concerns::ToJson

      attr_accessor :attributes, :associations, :localized_attributes, :base_url

      def initialize(attributes)
        @attributes = attributes.with_indifferent_access
      end

      def method_missing(name, *args, &block)
        _name = name.to_s
        if attributes.include?(_name)
          self[_name]
        elsif _name.end_with?('=') && attributes.include?(_name.chop)
          self[_name.chop] = args.first
        else
          super
        end
      end

      def respond_to?(name, include_private = false)
        attributes.include?(name.to_s) || super
      end

      def _id
        self['_id']
      end

      def []=(name, value)
        attributes[name] = value
      end

      def [](name)
        attributes[name]
      end

      def change(new_attributes)
        attributes.merge!((new_attributes || {}).with_indifferent_access)
        self
      end

      def serialize
        attributes.dup
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/models/entity.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/models/entity.rb