Sha256: 2260f7ee96cc7a1fff8f40b6f05e4310774a19d4e29aca73078c472c3168aa0a

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

module Smithy
  class PermittedParams < Struct.new(:params, :user)
    def params_for(param)
      param = param.to_sym
      attributes = send("#{param.to_s}_attributes".to_sym)
      if attributes == :all
        params.fetch(param, {}).permit!
      else
        params.fetch(param, {}).permit( *attributes )
      end
    end

    def asset_attributes
      [ :name, :file, :file_name, :file_url, :retained_file, :uploaded_file_url ]
    end

    def content_attributes
      [ :content ]
    end

    def content_block_attributes
      [ :name, :templates_attributes ]
    end

    def content_block_template_attributes
      [ :content, :name ]
    end

    def image_attributes
      [ :alternate_text, :asset_id, :height, :html_attributes, :image_scaling, :link_url, :width, :content ]
    end

    def page_attributes
      [ :browser_title, :cache_length, :description, :external_link, :keywords, :permalink, :publish, :published_at, :show_in_navigation, :title, :parent_id, :template_id ]
    end

    def page_content_attributes
      [ :label, :container, :content_block_type, :content_block_attributes, :content_block_template_id, :position ]
    end

    def page_list_attributes
      [ :count, :page_template_id, :parent_id, :include_children, :sort ]
    end

    def setting_attributes
      [ :name, :value ]
    end

    def template_attributes
      [ :name, :content, :template_type ]
    end

    def template_container_attributes
      [ :name, :position ]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smithycms-0.4.2 app/models/smithy/permitted_params.rb
smithycms-0.4.1 app/models/smithy/permitted_params.rb
smithycms-0.4.0 app/models/smithy/permitted_params.rb