Module: Stylish::Model::AccessorMethods

Defined in:
lib/stylish/models.rb

Instance Method Summary collapse

Instance Method Details

#as_json(*args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/stylish/models.rb', line 68

def as_json(*args)
  super.tap do |h|
    h.symbolize_keys!
    h.delete(:contents)

    if h[:path].is_a?(Hash)
      h[:path] = h[:path]['path']
    end
  end
end

#uidObject



64
65
66
# File 'lib/stylish/models.rb', line 64

def uid
  self.path if self.respond_to?(:path)
end

#update_attributes(attrs = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/stylish/models.rb', line 52

def update_attributes(attrs={})
  writers = self.class.allowed_writer_methods.map(&:to_s)
  keys = writers & attrs.keys.map {|k| "#{k}=" }

  keys.each do |key|
    value = attrs[key.gsub(/=$/,'')]
    self.send(key, value)
  end

  !!(save)
end