Sha256: 8f7da7b477d9f2cae8cb62ee1feefae6e8457ab6067624ffa5aa53bd84886e18

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module BitPlayer
  module ContentProviders::ViewProvider
    def self.included(base)
      base.class_eval do
        def self.data_class(klass)
          @source_class = klass
        end

        def self.source_class
          @source_class || fail("Classes inheriting from #{ self } must define a source class with `data_class <class>`")
        end

        def self.show_nav_link
          @show_nav_link = true
        end

        def self.hide_nav_link
          @show_nav_link = false
        end

        def self.show_nav_link?
          @show_nav_link
        end

        def self.view_type(type)
          unless ["show", "index"].include?(type)
            fail("view type must be one of 'show', 'index'")
          end
          @view_type = type
        end

        def self.get_view_type
          @view_type
        end
      end
    end

    def show_nav_link?
      self.class.show_nav_link?
    end

    def template
      "#{ plural_name }/#{ self.class.get_view_type }"
    end

    private

    def plural_name
      self.class.source_class.to_s.underscore.pluralize
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bit_player-0.1.3 app/models/bit_player/content_providers/view_provider.rb
bit_player-0.1.2 app/models/bit_player/content_providers/view_provider.rb
bit_player-0.1.1 app/models/bit_player/content_providers/view_provider.rb