Class: Maglev::Theme::StyleSetting

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/maglev/theme/style_setting.rb

Overview

rubocop:disable Style/ClassAndModuleChildren

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

attributes ##



9
10
11
# File 'app/models/maglev/theme/style_setting.rb', line 9

def default
  @default
end

#idObject

validations ##



9
10
11
# File 'app/models/maglev/theme/style_setting.rb', line 9

def id
  @id
end

#labelObject

attributes ##



9
10
11
# File 'app/models/maglev/theme/style_setting.rb', line 9

def label
  @label
end

#optionsObject

attributes ##



9
10
11
# File 'app/models/maglev/theme/style_setting.rb', line 9

def options
  @options
end

#typeObject

attributes ##



9
10
11
# File 'app/models/maglev/theme/style_setting.rb', line 9

def type
  @type
end

Class Method Details

.build(hash) ⇒ Object

class methods ##



32
33
34
35
36
37
# File 'app/models/maglev/theme/style_setting.rb', line 32

def self.build(hash)
  attributes = hash.slice('id', 'label', 'type', 'default')
  options = hash.except('id', 'label', 'type', 'default')

  new(attributes.merge(options: options))
end

.build_many(list) ⇒ Object



39
40
41
# File 'app/models/maglev/theme/style_setting.rb', line 39

def self.build_many(list)
  list.map { |hash| build(hash) }
end

Instance Method Details

#build_default_checkbox_content(default) ⇒ Object



27
28
29
# File 'app/models/maglev/theme/style_setting.rb', line 27

def build_default_checkbox_content(default)
  !default.nil?
end

#build_default_content(custom_default = nil) ⇒ Object

NOTE: any modification to that method must be reflected to the JS editor



18
19
20
21
22
23
24
25
# File 'app/models/maglev/theme/style_setting.rb', line 18

def build_default_content(custom_default = nil)
  default = custom_default || self.default
  case type.to_sym
  when :checkbox then build_default_checkbox_content(default)
  else
    default || label
  end
end