Class: Pageflow::Widget

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/pageflow/widget.rb

Defined Under Namespace

Classes: Resolver

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.batch_update!(widgets_attributes) ⇒ Object


29
30
31
32
33
# File 'app/models/pageflow/widget.rb', line 29

def self.batch_update!(widgets_attributes)
  widgets_attributes.each do |attributes|
    find_or_initialize_by(role: attributes[:role]).update!(attributes)
  end
end

.copy_all_to(subject) ⇒ Object


23
24
25
26
27
# File 'app/models/pageflow/widget.rb', line 23

def self.copy_all_to(subject)
  all.each do |widget|
    widget.copy_to(subject)
  end
end

.resolve(options = {}) ⇒ Object


35
36
37
# File 'app/models/pageflow/widget.rb', line 35

def self.resolve(options = {})
  Resolver.new(options).result
end

Instance Method Details

#copy_to(subject) ⇒ Object


7
8
9
10
11
# File 'app/models/pageflow/widget.rb', line 7

def copy_to(subject)
  record = dup
  record.subject = subject
  record.save!
end

#enabled?(options) ⇒ Boolean


13
14
15
# File 'app/models/pageflow/widget.rb', line 13

def enabled?(options)
  options[:only] != :editor || widget_type.enabled_in_editor?
end

#widget_typeObject


17
18
19
20
21
# File 'app/models/pageflow/widget.rb', line 17

def widget_type
  Pageflow.config.widget_types.fetch_by_name(type_name) do
    WidgetType::Null.new(role)
  end
end