Sha256: a7122e2a1bb06a549ca4c22a97dd506ec11e8ecc06e5bb2006cd4d8397670251

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

module ActsAsAssetable
  def self.included(base)
    base.extend ClassMethods
  end
  
  module ClassMethods
    
    def acts_as_assetable_on(*args)
      options = args.extract_options!
      styles  = args
      acts_as_joinable_on :assets, :contexts => styles
      self.class_eval do
        styles.each do |k,v|
          name = "#{k.to_s}_image"
          define_method name do
            join_for(k)
          end
          
          define_method "#{name}_id" do
            result = join_for(k)
            result ? result.id : nil
          end
          
          define_method "#{name}=" do |asset|
            set_joined(k, asset)
          end
          
          define_method "#{name}_id=" do |id|
            set_joined(k, id)
          end
        end
      end
    end
    
    def acts_as_assetable(*args)
      acts_as_assetable_on(*args)
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts-as-assetable-0.0.1.5 lib/acts-as-assetable.rb