Class: Hanswurst

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
CouchPotato::Persistence, Callbacks, MethodMissing
Defined in:
lib/hanswurst.rb,
lib/hanswurst/as.rb,
lib/hanswurst/doc.rb,
lib/hanswurst/shares.rb,
lib/hanswurst/callbacks.rb,
lib/hanswurst/delegates.rb,
lib/hanswurst/class_methods.rb,
lib/hanswurst/method_missing.rb,
lib/hanswurst/instance_methods.rb

Overview

TODO allow subclasses of Hanswurst to have the role registry (or handle it via callback)

Defined Under Namespace

Modules: Callbacks, ClassMethods, Delegates, Doc, MethodMissing, Shares Classes: As

Instance Method Summary collapse

Methods included from ClassMethods

getClass, method_missing, register_role, role_class, role_list, role_view

Methods included from Callbacks

included

Methods included from MethodMissing

#method_missing

Constructor Details

#initialize(hsh = {}) ⇒ Hanswurst

Returns a new instance of Hanswurst.



2
3
4
5
6
7
8
# File 'lib/hanswurst/instance_methods.rb', line 2

def initialize(hsh={})
  unless hsh.empty?
    hsh.each do |role, obj|
      self.send(:"#{role}=", obj)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hanswurst::MethodMissing

Instance Method Details

#<<(hsh) ⇒ Object



26
27
28
# File 'lib/hanswurst/instance_methods.rb', line 26

def <<(hsh)
  add_roles(hsh)
end

#copyObject

copy the doc including the roles



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hanswurst/instance_methods.rb', line 11

def copy()
  attributes = self.to_hash
  attributes.delete "ruby_class"
  attributes.delete "_id"
  attributes.delete "_rev"
  attributes.delete :created_at
  attributes.delete :updated_at
  hanswust_data = attributes.delete :hanswurst_data
  obj = self.class.new attributes
  hanswust_data.each do |role,val|
    obj.send(:"#{role}=", val.dup)
  end
  obj
end

#update_roles!Object

a hack around api.rubyonrails.org/classes/ActiveModel/Dirty.html since ActiveModel::Dirty does not recognize when property is a hash and hashentries do change



32
33
34
35
# File 'lib/hanswurst/instance_methods.rb', line 32

def update_roles!
  self.hanswurst_data_will_change!
  true
end