Module: Dox::Api::ResourceModel

Extended by:
ActiveSupport::Concern
Included in:
Auth::App, Auth::Authorization, Auth::GuestUser, Auth::Org, Auth::PasswordReset, Auth::User
Defined in:
lib/dox/api/resource_model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attributesObject


39
40
41
42
43
44
45
46
47
# File 'lib/dox/api/resource_model.rb', line 39

def attributes
  attrs = {}

  self.class.attributes.each do |name|
    attrs[name] = public_send(name)
  end

  attrs
end

#attributes=(attrs) ⇒ Object


49
50
51
52
53
# File 'lib/dox/api/resource_model.rb', line 49

def attributes=(attrs)
  attrs.each do |name, value|
    public_send("#{name}=", value)
  end
end

#errors_from_json(json) ⇒ Object


67
68
69
70
71
72
73
# File 'lib/dox/api/resource_model.rb', line 67

def errors_from_json(json)
  hsh = ActiveSupport::JSON.decode(json)

  Array(hsh["attrs"]).each do |name, value|
    self.errors.add(name, value)
  end
end

#from_json(json) ⇒ Object


63
64
65
# File 'lib/dox/api/resource_model.rb', line 63

def from_json(json)
  super
end

#hrefObject

Raises:

  • (NotImplementedError)

55
56
57
# File 'lib/dox/api/resource_model.rb', line 55

def href
  raise NotImplementedError, "href needs to be implemented by #{self.class}"
end

#initialize(attrs = {}) ⇒ Object


35
36
37
# File 'lib/dox/api/resource_model.rb', line 35

def initialize(attrs = {})
  self.attributes = attrs
end

#to_jsonObject


59
60
61
# File 'lib/dox/api/resource_model.rb', line 59

def to_json
  super
end