Class: Backend::TimelineHelper::Timeline::Side

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/backend/timeline_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeline, name, model, options = {}) ⇒ Side

Returns a new instance of Side.


27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/backend/timeline_helper.rb', line 27

def initialize(timeline, name, model, options = {})
  @timeline = timeline
  @name = name
  @model = model
  @label_method = options[:label_method]
  @at_method = options[:at] || options[:at_method] || :created_at
  @label = options[:label]
  @new = !options[:new].is_a?(FalseClass)
  @params = options[:params] || {}
  @authorization_proc = options[:if]
end

Instance Attribute Details

#at_methodObject (readonly)

Returns the value of attribute at_method


25
26
27
# File 'app/helpers/backend/timeline_helper.rb', line 25

def at_method
  @at_method
end

#label_methodObject (readonly)

Returns the value of attribute label_method


25
26
27
# File 'app/helpers/backend/timeline_helper.rb', line 25

def label_method
  @label_method
end

#modelObject (readonly)

Returns the value of attribute model


25
26
27
# File 'app/helpers/backend/timeline_helper.rb', line 25

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name


25
26
27
# File 'app/helpers/backend/timeline_helper.rb', line 25

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params


87
88
89
# File 'app/helpers/backend/timeline_helper.rb', line 87

def params
  @params
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'app/helpers/backend/timeline_helper.rb', line 55

def authorized?
  @authorization_proc.nil? || @authorization_proc.call(object)
end

#controller_nameObject


47
48
49
# File 'app/helpers/backend/timeline_helper.rb', line 47

def controller_name
  @controller_name ||= model.name.tableize.to_s
end

#countObject


63
64
65
# File 'app/helpers/backend/timeline_helper.rb', line 63

def count
  @count ||= records.count
end

#human_nameObject


39
40
41
# File 'app/helpers/backend/timeline_helper.rb', line 39

def human_name
  @label
end

#model_nameObject


43
44
45
# File 'app/helpers/backend/timeline_helper.rb', line 43

def model_name
  @model_name ||= model.name.underscore.to_sym
end

#new_url?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'app/helpers/backend/timeline_helper.rb', line 51

def new_url?
  @new
end

#objectObject


59
60
61
# File 'app/helpers/backend/timeline_helper.rb', line 59

def object
  @timeline.object
end

#recordsObject


83
84
85
# File 'app/helpers/backend/timeline_helper.rb', line 83

def records
  @records ||= @timeline.object.send(@name)
end

#stepsObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/backend/timeline_helper.rb', line 67

def steps
  unless @steps
    @steps = records.collect do |record|
      SideStep.new(self, record.send(at_method), record)
    end
    @timeline.others.each do |other|
      other.send(@name).collect do |record|
        unless @steps.detect { |s| s.record == record }
          @steps << SideStep.new(self, record.send(at_method), record)
        end
      end
    end
  end
  @steps
end