Sha256: 6c739c9ca5d3fe251d8f9247c05a0e4c736e2fc50bd4a79034154f158ef7175e

Contents?: true

Size: 638 Bytes

Versions: 6

Compression:

Stored size: 638 Bytes

Contents

module RademadeAdmin
  module Hideable

    STATUS_HIDDEN = 0
    STATUS_SHOWN = 1

    def method_missing(name, *arguments)
      if %w(status status=).include? name
        raise NotImplementedError.new "Implement '#{name}' method"
      end
      super
    end

    def shown?
      item_status = send(:status)
      if item_status.is_a? Fixnum
        item_status == STATUS_SHOWN
      else
        # for boolean values
        item_status
      end
    end

    def show
      send(:status=, STATUS_SHOWN)
    end

    def hide
      send(:status=, STATUS_HIDDEN)
    end

    def toggle
      shown? ? hide : show
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rademade_admin-0.2.2 lib/rademade_admin/hideable.rb
rademade_admin-0.2.1 lib/rademade_admin/hideable.rb
rademade_admin-0.2.0 lib/rademade_admin/hideable.rb
rademade_admin-0.1.6 lib/rademade_admin/hideable.rb
rademade_admin-0.1.5 lib/rademade_admin/hideable.rb
rademade_admin-0.1.4 lib/rademade_admin/hideable.rb