Class: Sipity::Decorators::SipDecorator

Inherits:
Draper::Decorator
  • Object
show all
Defined in:
app/decorators/sipity/decorators/sip_decorator.rb

Overview

A decoration layer for Sipity::Sip

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.object_classObject


5
6
7
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 5

def self.object_class
  Models::Sip
end

Instance Method Details

#authors(decorator: Decorators::CollaboratorDecorator) ⇒ Object


31
32
33
34
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 31

def authors(decorator: Decorators::CollaboratorDecorator)
  Queries::CollaboratorQueries.
    sip_collaborators_for(sip: object, role: 'author').map { |obj| decorator.decorate(obj) }
end

#available_linked_actionsObject


36
37
38
39
40
41
42
43
44
45
46
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 36

def available_linked_actions
  # TODO: This is dependent on object state
  # TODO: What to do when I have a non-persisted state? Can this decorator
  #   be applied?
  [
    LinkedAction.new(
      label: "Edit #{model.title}", path: h.edit_sip_path(object),
      html_options: { 'class' => 'btn btn-primary action-edit' }
    )
  ]
end

#fieldset_for(name) ⇒ Object


11
12
13
14
15
16
17
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 11

def fieldset_for(name)
  # TODO: Translate name following active record internationalization
  # conventions.
  h.field_set_tag(name, class: h.dom_class(object, name)) do
    yield
  end
end

#human_attribute_name(name) ⇒ Object


27
28
29
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 27

def human_attribute_name(name)
  object.class.human_attribute_name(name)
end

#recommendation_for(name) ⇒ Object (private)


50
51
52
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 50

def recommendation_for(name)
  Recommendations.const_get("#{name.classify}Recommendation").new(sip: self)
end

#to_sObject


19
20
21
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 19

def to_s
  title
end

#with_recommendation(recommendation_name) {|recommendation_for(recommendation_name)| ... } ⇒ Object

Yields:


23
24
25
# File 'app/decorators/sipity/decorators/sip_decorator.rb', line 23

def with_recommendation(recommendation_name)
  yield(recommendation_for(recommendation_name))
end