Sha256: 33c236a3edff1e111488b82b10f33608cb131fc88b4fa125062d278b98808a21

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

Contents

module ActiveGit
  module ActiveRecord

    module ClassMethods

      def git_versioned
        ActiveGit.models << self

        after_save do |record|
          Synchronizer.synchronize FileSave.new(record)
        end

        after_destroy do |record|
          Synchronizer.synchronize FileDelete.new(record)
        end

        def from_json(json)
          record = self.new
          hash = json.is_a?(Hash) ? json : JSON.parse(json)
          hash.each do |attr, value|
            if record.respond_to? "#{attr}="
              if self.columns_hash[attr].type == :datetime
                record.send("#{attr}=", Time.parse(value).utc)
              else
                record.send("#{attr}=", value)
              end
            end
          end
          record
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_git-0.0.5 lib/active_git/active_record_extension.rb
active_git-0.0.4 lib/active_git/active_record_extension.rb