Sha256: 32b83126b840701e98b99dffa835091ded034abd398c8662f28a86eaf6c25301

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 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.2.0 lib/acts-as-assetable/acts_as_assetable.rb