Sha256: f0734f1a30e014c7cdf0b88ab59997a128a95ad6a730d35441c089a199d0325a

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module BitPlayer
  module ContentProviders::FormViewProvider
    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 ["new", "edit"].include?(type)
            fail("view type must be one of 'new', 'edit'")
          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/form_view_provider.rb
bit_player-0.1.2 app/models/bit_player/content_providers/form_view_provider.rb
bit_player-0.1.1 app/models/bit_player/content_providers/form_view_provider.rb