Sha256: 122812e2049f86a693045077b01a0d07f3b9a00f2ffe22c6800cf5365b746ed7

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 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!
      elsif attributes.respond_to? :call
        attributes.call
      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: [ :id, :name, :content, :_destroy ] ]
      :all
    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_template_id, :position ]
      :all
    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

10 entries across 10 versions & 1 rubygems

Version Path
smithycms-0.5.99.3 app/models/smithy/permitted_params.rb
smithycms-0.5.99.2 app/models/smithy/permitted_params.rb
smithycms-0.5.99.1 app/models/smithy/permitted_params.rb
smithycms-0.5.99 app/models/smithy/permitted_params.rb
smithycms-0.5.2 app/models/smithy/permitted_params.rb
smithycms-0.5.1 app/models/smithy/permitted_params.rb
smithycms-0.5.0 app/models/smithy/permitted_params.rb
smithycms-0.4.5 app/models/smithy/permitted_params.rb
smithycms-0.4.4 app/models/smithy/permitted_params.rb
smithycms-0.4.3 app/models/smithy/permitted_params.rb