Sha256: 56025508f1c1753cc658828ad181994c55a764642145d1e29c4d78f04130044c
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module ActiveMetadata CONFIG = File.exists?('config/active_metadata.yml') ? YAML.load_file('config/active_metadata.yml')[Rails.env] : {} ## Define ModelMethods module Base require 'paperclip' require "active_metadata/persistence/persistence" def self.included(klass) klass.class_eval do extend Config end end module Config def acts_as_metadata *args after_save :save_history class_variable_set("@@metadata_id_from", args.empty? ? nil : args[0][:metadata_id_from]) include ActiveMetadata::Base::InstanceMethods include ActiveMetadata::Persistence end end module InstanceMethods def metadata_id metadata_id_from = self.class.class_variable_get("@@metadata_id_from") return self.id if metadata_id_from.nil? receiver = self metadata_id_from.each do |item| receiver = receiver.send item end receiver.id end def current_user_id if User.respond_to?(:current) && !User.current.nil? User.current.id else nil end end end # InstanceMethods end end ::ActiveRecord::Base.send :include, ActiveMetadata::Base
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_metadata-0.2.0 | lib/active_metadata/base.rb |