Class: Pageflow::Widget

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

Defined Under Namespace

Classes: Resolver

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#widget_typeObject

Returns the value of attribute widget_type.



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

def widget_type
  @widget_type
end

Class Method Details

.batch_update!(widgets_attributes) ⇒ Object



31
32
33
34
35
# File 'app/models/pageflow/widget.rb', line 31

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



25
26
27
28
29
# File 'app/models/pageflow/widget.rb', line 25

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

.resolve(config, options = {}) ⇒ Object



37
38
39
# File 'app/models/pageflow/widget.rb', line 37

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

Instance Method Details

#copy_to(subject) ⇒ Object



9
10
11
12
13
# File 'app/models/pageflow/widget.rb', line 9

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

#enabled?(options) ⇒ Boolean

Returns:

  • (Boolean)


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

def enabled?(options)
  if options[:scope] == :editor
    widget_type.enabled_in_editor?
  elsif options[:scope] == :preview
    widget_type.enabled_in_preview?
  else
    true
  end
end