Sha256: 04da7a5e708803ef852a8c5213ca06bbe8e05cdbc70ff3c679ad15247ac40409

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

module RearHelpers
  module InstanceMixin
    
    attr_reader   :items
    attr_accessor :item, :item_id, :column

    def orm
      @__rear__orm ||= RearORM.new(__rear__.model, __rear__.pkey)
    end

    def dom_id
      @__rear__dom_id ||= (params[:dom_id] || # params[:dom_id] are used by decorative filters
        (@reverse_assoc ? @reverse_assoc.dom_id : 'rear_element_%s' % self.__id__)).freeze
    end

    def model
      __rear__.model
    end

    def sequel?
      @@__rear__is_sequel ||= RearUtils.orm(model) == :sq
    end

    def pkey
      __rear__.pkey
    end

    def assocs *types
      return __rear__.assocs if types.empty?
      types.inject({}) do |assocs,type|
        assocs.merge(__rear__.assocs[type.to_sym] || {})
      end
    end

    def template_cache template
      ((@__rear__template_cache ||= {})[template] ||= {})[File.mtime(template)] ||= File.read(template)
    end

    # used for cosmetic compatibility between filters and columns.
    # columns block are executed inside Column instance,
    # and using `options` method to define options for :select/:radio/:checkbox columns.
    # filters of these types also uses a block and it is executed in controller's context.
    # so adding this method here will allow to use `options` method inside filter's block.
    #
    # @example
    #   filter :colors do
    #     options 'Red', 'Green', 'Blue'
    #   end
    #   # this is equivalent to 
    #   filter :colors do
    #     ['Red', 'Green', 'Blue']
    #   end
    #   # but looks cosmetically better cause uses same syntax as columns
    #
    def options *args
      args
    end

    def associated_model_controller model
      (@__rear__associated_model_controllers ||= {})[model] ||=
        RearUtils.associated_model_controller(model, :ensure_mounted)
    end

    def __rear__
      self.class
    end

    def readonly?
      self.class.readonly?
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rear-0.2.0 lib/rear/helpers/generic.rb