Sha256: 286fed1027c841a03d28347295b08be7156eb630d36f21c1d202a5d6fb06cba3

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

module ActiveGit
  module ActiveRecord

    module ClassMethods

      def git_versioned
        ActiveGit.models << self

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

        after_destroy do |record|
          ActiveGit.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.7 lib/active_git/active_record_extension.rb
active_git-0.0.6 lib/active_git/active_record_extension.rb