Class: Cms::Asset::Meta

Inherits:
Object
  • Object
show all
Defined in:
app/models/cms/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Meta

Returns a new instance of Meta.



18
19
20
21
# File 'app/models/cms/asset.rb', line 18

def initialize(data)
  @name, @value = data[:name], data[:value]
  @errors = ActiveModel::Errors.new(self)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



16
17
18
# File 'app/models/cms/asset.rb', line 16

def errors
  @errors
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'app/models/cms/asset.rb', line 16

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



16
17
18
# File 'app/models/cms/asset.rb', line 16

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'app/models/cms/asset.rb', line 23

def valid?
  validate
  errors.empty?
end

#validateObject



28
29
30
31
32
33
34
35
# File 'app/models/cms/asset.rb', line 28

def validate
  errors.clear
  if @name.blank?
    errors.add :name, 'must be set'
  else
    errors.add :name, "is an invalid format" if (@name =~ /^[a-z]+[a-z0-9_]*$/).nil?
  end
end