Class: Releaf::ResourceParams

Inherits:
ResourceBase show all
Defined in:
app/lib/releaf/resource_params.rb

Instance Attribute Summary

Attributes inherited from ResourceBase

#resource_class

Instance Method Summary collapse

Methods inherited from ResourceBase

#association_excluded_attributes, #associations, #excluded_associations, #excluded_attributes, #includable_association?, #includable_association_types, #initialize, #localized_attributes?, title, title_methods, #values

Constructor Details

This class inherits a constructor from Releaf::ResourceBase

Instance Method Details

#association_attributes(association) ⇒ Object


44
45
46
# File 'app/lib/releaf/resource_params.rb', line 44

def association_attributes(association)
  super + ["id", "_destroy"]
end

#associations_attributesObject


38
39
40
41
42
# File 'app/lib/releaf/resource_params.rb', line 38

def associations_attributes
  associations.collect do |association|
    {"#{association.name}_attributes" => association_attributes(association)}
  end
end

#base_attributesObject


16
17
18
19
20
21
22
23
24
# File 'app/lib/releaf/resource_params.rb', line 16

def base_attributes
  super.inject([]) do|list, attribute|
    if file_attribute?(attribute)
      list + file_attribute_params(attribute)
    else
      list << attribute
    end
  end
end

#file_attribute?(column) ⇒ Boolean

Returns:

  • (Boolean)

7
8
9
# File 'app/lib/releaf/resource_params.rb', line 7

def file_attribute?(column)
  file_attributes.include? column
end

#file_attribute_params(column) ⇒ Object


11
12
13
14
# File 'app/lib/releaf/resource_params.rb', line 11

def file_attribute_params(column)
  file_field = column.sub(/_uid$/, "")
  [file_field, "retained_#{file_field}", "remove_#{file_field}"]
end

#file_attributesObject


3
4
5
# File 'app/lib/releaf/resource_params.rb', line 3

def file_attributes
  resource_class.dragonfly_attachment_classes.collect{|c| "#{c.attribute}_uid" }
end

#localized_attribute_params(column) ⇒ Object


32
33
34
35
36
# File 'app/lib/releaf/resource_params.rb', line 32

def localized_attribute_params(column)
  resource_class.globalize_locales.collect do|locale|
    "#{column}_#{locale}"
  end
end

#localized_attributesObject


26
27
28
29
30
# File 'app/lib/releaf/resource_params.rb', line 26

def localized_attributes
  super.inject([]) do |list, column|
    list + localized_attribute_params(column)
  end
end