Module: Vidibus::Resource::Consumer::Mongoid::ClassMethods

Defined in:
lib/vidibus/resource/consumer/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#ensure!(conditions) ⇒ Object

Ensures that an instance with given conditions exists.



78
79
80
# File 'lib/vidibus/resource/consumer/mongoid.rb', line 78

def ensure!(conditions)
  self.where(conditions).first || self.create!(conditions)
end

#remove(conditions) ⇒ Object

Remove all intances with given conditions.



83
84
85
86
87
88
# File 'lib/vidibus/resource/consumer/mongoid.rb', line 83

def remove(conditions)
  existing = self.where(conditions).to_a
  for instance in existing
    instance.destroy
  end
end

#resource_provider(service, realm = nil) ⇒ Object

Sets up resource provider service type and realm.



66
67
68
69
# File 'lib/vidibus/resource/consumer/mongoid.rb', line 66

def resource_provider(service, realm = nil)
  @resource_provider = service
  resource_realm(realm) if realm
end

#resource_realm(realm) ⇒ Object

Sets up realm of resource. If no realm has been set up class-wide, the attribute :realm_uuid will be used.



73
74
75
# File 'lib/vidibus/resource/consumer/mongoid.rb', line 73

def resource_realm(realm)
  @resource_realm = realm
end