Module: FriendlyAttributes::ClassMethods

Defined in:
lib/friendly_attributes/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#friendly_details(klass, attributes) ⇒ DetailsDelegator #friendly_details(klass, attributes, options) ⇒ DetailsDelegator

Configure a Friendly Base model associated with an ActiveRecord model.

Overloads:

  • #friendly_details(klass, attributes) ⇒ DetailsDelegator

    Parameters:

    • klass (Class)

      FriendlyAttributes::Base instance used to extend the ActiveRecord model

    • attributes (Hash)

      hash of types and attributes names with which to extend the ActiveRecord, through FriendlyAttributes::Base

  • #friendly_details(klass, attributes, options) ⇒ DetailsDelegator

    Parameters:

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/friendly_attributes/class_methods.rb', line 13

def friendly_details(*args, &block)
  klass = args.shift
  options = args.extract_options!
  attributes = args.extract_options!
  if attributes.empty?
    attributes = options
    options = {}
  end
  
  DetailsDelegator.new(klass, self, attributes, options, &block).tap do |dd|
    dd.setup_delegated_attributes
    dd.instance_eval(&block) if block_given?
  end
end

#friendly_mount_uploader(name, klass) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/friendly_attributes/class_methods.rb', line 28

def friendly_mount_uploader(name, klass)
  mount_uploader name, klass
  
  instance_eval do
    alias_method :read_uploader, :read_friendly_attribute
    alias_method :write_uploader, :write_friendly_attribute
  end
end