Module: Marquery::Model

Included in:
Entry
Defined in:
lib/marquery/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



13
14
15
# File 'lib/marquery/model.rb', line 13

def content
  @content
end

#dateObject (readonly)

Returns the value of attribute date.



13
14
15
# File 'lib/marquery/model.rb', line 13

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



13
14
15
# File 'lib/marquery/model.rb', line 13

def description
  @description
end

#slugObject (readonly)

Returns the value of attribute slug.



13
14
15
# File 'lib/marquery/model.rb', line 13

def slug
  @slug
end

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/marquery/model.rb', line 13

def source
  @source
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/marquery/model.rb', line 13

def title
  @title
end

Class Method Details

.included(base) ⇒ Object



8
9
10
11
# File 'lib/marquery/model.rb', line 8

def self.included(base)
  base.include(Marquery::Renderable)
  base.include(Marquery::Attributable)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



23
24
25
# File 'lib/marquery/model.rb', line 23

def ==(other)
  other.is_a?(self.class) && other.slug == slug
end

#active?Boolean

Returns:

  • (Boolean)


21
# File 'lib/marquery/model.rb', line 21

def active? = @active

#hashObject



28
# File 'lib/marquery/model.rb', line 28

def hash = [self.class, slug].hash

#initialize(attrs = {}) ⇒ Object



15
16
17
18
19
# File 'lib/marquery/model.rb', line 15

def initialize(attrs = {})
  attrs = attrs.transform_keys(&:to_sym)
  assign_standard_attributes(attrs)
  assign_declared_attributes(attrs)
end

#to_hObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/marquery/model.rb', line 30

def to_h
  {
    slug:,
    title:,
    description:,
    content:,
    date:,
    active: active?,
    source:,
    assets:
  }.tap do |base|
    self.class.attributes.each_key do |name|
      base[name] = public_send(name)
    end
  end
end