Class: Maglev::Section

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Serializers::JSON, ContentConcern
Defined in:
app/models/maglev/section.rb

Defined Under Namespace

Modules: ContentConcern Classes: Block, Setting, Store

Constant Summary collapse

HASH_ATTRIBUTES =
%w[id theme name site_scoped singleton viewport_fixed_position insert_button max_width_pane
insert_at category blocks_label blocks_presentation sample screenshot_timestamp].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentConcern

#build_default_content

Instance Attribute Details

#blocksObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def blocks
  @blocks
end

#blocks_labelObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def blocks_label
  @blocks_label
end

#blocks_presentationObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def blocks_presentation
  @blocks_presentation
end

#categoryObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def category
  @category
end

#idObject

validations ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def id
  @id
end

#insert_atObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def insert_at
  @insert_at
end

#insert_buttonObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def insert_button
  @insert_button
end

#max_width_paneObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def max_width_pane
  @max_width_pane
end

#nameObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def name
  @name
end

#sampleObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def sample
  @sample
end

#screenshot_timestampObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def screenshot_timestamp
  @screenshot_timestamp
end

#settingsObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def settings
  @settings
end

#singletonObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def singleton
  @singleton
end

#site_scopedObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def site_scoped
  @site_scoped
end

#themeObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def theme
  @theme
end

#viewport_fixed_positionObject

attributes ##



13
14
15
# File 'app/models/maglev/section.rb', line 13

def viewport_fixed_position
  @viewport_fixed_position
end

Class Method Details

.build(hash) ⇒ Object

class methods ##



39
40
41
42
43
44
45
46
47
48
# File 'app/models/maglev/section.rb', line 39

def self.build(hash)
  attributes = prepare_attributes(hash)

  new(
    attributes.merge(
      settings: ::Maglev::Section::Setting.build_many(hash['settings']),
      blocks: ::Maglev::Section::Block.build_many(hash['blocks'])
    )
  )
end

.prepare_attributes(hash) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/maglev/section.rb', line 50

def self.prepare_attributes(hash)
  attributes = hash.slice(*HASH_ATTRIBUTES)

  %w[site_scoped singleton viewport_fixed_position max_width_pane].each do |name|
    attributes[name] = false if attributes[name].nil?
  end

  attributes['insert_button'] = true if attributes['insert_button'].nil?

  attributes
end

Instance Method Details

#singleton?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/maglev/section.rb', line 30

def singleton?
  !!singleton
end

#site_scoped?Boolean

methods ##

Returns:

  • (Boolean)


26
27
28
# File 'app/models/maglev/section.rb', line 26

def site_scoped?
  !!site_scoped
end

#viewport_fixed_position?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/maglev/section.rb', line 34

def viewport_fixed_position?
  !!viewport_fixed_position?
end