Class: RiddlerAdmin::Element

Inherits:
ApplicationRecord show all
Defined in:
app/models/riddler_admin/element.rb

Constant Summary collapse

MODEL_KEY =
"el".freeze
ID_LENGTH =

56_800_235_584 per second

6

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_classesObject



21
22
23
24
25
26
27
28
29
# File 'app/models/riddler_admin/element.rb', line 21

def self.available_classes
  [
    Elements::Heading,
    Elements::Image,
    Elements::Link,
    Elements::Text,
    Elements::Variant
  ]
end

.default_classObject



31
32
33
# File 'app/models/riddler_admin/element.rb', line 31

def self.default_class
  Elements::Text
end

.short_nameObject



35
36
37
# File 'app/models/riddler_admin/element.rb', line 35

def self.short_name
  name.demodulize
end

Instance Method Details

#content_idObject



56
57
58
# File 'app/models/riddler_admin/element.rb', line 56

def content_id
  id
end

#content_typeObject



52
53
54
# File 'app/models/riddler_admin/element.rb', line 52

def content_type
  "element"
end

#definition_hash(options = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'app/models/riddler_admin/element.rb', line 60

def definition_hash options=nil
  options ||= {}
  hash = serializable_hash options.merge(serializable_hash_options)
  hash["type"] = object
  hash.delete "include_predicate" if hash["include_predicate"].blank?
  hash
end

#excluded_attrsObject



75
76
77
# File 'app/models/riddler_admin/element.rb', line 75

def excluded_attrs
  [:created_at, :updated_at, :container_type, :container_id, :position, :url, :text]
end

#objectObject

Used in serialization



48
49
50
# File 'app/models/riddler_admin/element.rb', line 48

def object
  type.demodulize.underscore
end

#serializable_hash_optionsObject



68
69
70
71
72
73
# File 'app/models/riddler_admin/element.rb', line 68

def serializable_hash_options
  {
    methods: [:content_type],
    except: excluded_attrs
  }
end

#short_nameObject



43
44
45
# File 'app/models/riddler_admin/element.rb', line 43

def short_name
  self.class.short_name
end

#stepObject



79
80
81
82
83
84
85
# File 'app/models/riddler_admin/element.rb', line 79

def step
  if container.kind_of? ::RiddlerAdmin::Step
    container
  else
    container.step
  end
end

#to_partial_path(detail = nil) ⇒ Object



39
40
41
# File 'app/models/riddler_admin/element.rb', line 39

def to_partial_path detail=nil
  [self.class.name.underscore, detail].compact.join "/"
end