Module: CouchVisible

Extended by:
Config
Defined in:
lib/couch_visible/config.rb,
lib/couch_visible/couch_visible.rb,
lib/couch_visible/maps/by_shown.rb,
lib/couch_visible/maps/by_hidden.rb,
lib/couch_visible/conditions/published.rb,
lib/couch_visible/conditions/unpublished.rb,
lib/couch_visible/integrations/couch_publish.rb

Defined Under Namespace

Modules: Conditions, Config, CouchPublish, ModelClassMethods Classes: ByHidden, ByShown

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

hide_by_default!, hide_by_default?, reset!, show_by_default!, show_by_default?

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/couch_visible/couch_visible.rb', line 3

def self.included(base) 
  base.send :include, ::CouchView unless base.ancestors.include?(::CouchView)
  base.extend ModelClassMethods
  base.property :couch_visible, TrueClass

  base.couch_view :by_hidden do
    map CouchVisible::ByHidden
  end

  base.couch_view :by_shown do
    map CouchVisible::ByShown
  end
  
  base.before_create do |doc|
    doc.couch_visible = doc.class.show_by_default? if doc.couch_visible.nil?
    true
  end

  if defined?(Memories) && base.ancestors.include?(Memories)
    base.forget :couch_visible
  end

  if defined?(::CouchPublish) && base.ancestors.include?(::CouchPublish)
    base.send :include, CouchVisible::CouchPublish
  end
end

Instance Method Details

#hidden?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/couch_visible/couch_visible.rb', line 66

def hidden?
  couch_visible != true
end

#hideObject



75
76
77
# File 'lib/couch_visible/couch_visible.rb', line 75

def hide
  self.couch_visible = false
end

#hide!Object



70
71
72
73
# File 'lib/couch_visible/couch_visible.rb', line 70

def hide!
  self.couch_visible = false
  self.save!
end

#showObject



84
85
86
# File 'lib/couch_visible/couch_visible.rb', line 84

def show
  self.couch_visible = true
end

#show!Object



79
80
81
82
# File 'lib/couch_visible/couch_visible.rb', line 79

def show!
  self.couch_visible = true
  self.save!
end

#shown?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/couch_visible/couch_visible.rb', line 62

def shown?
  couch_visible == true
end