Module: RubyHaze::Persisted::ClassMethods

Defined in:
lib/rubyhaze/persisted/model.rb

Instance Method Summary collapse

Instance Method Details

#[](*args) ⇒ Object



239
240
241
242
243
# File 'lib/rubyhaze/persisted/model.rb', line 239

def [](*args)
  options = args.extract_options!
  options[:uid] = args.first if RubyHaze.valid_uuid?(args.first)
  find(options).first
end

#attribute(name, type, options = {}) ⇒ Object



227
228
229
230
231
232
233
# File 'lib/rubyhaze/persisted/model.rb', line 227

def attribute(name, type, options = {})
  raise "Attribute [#{name}] already defined" if attribute_names.include?(name)
  @attributes << [name, type, options]
  @attribute_methods_generated = false
  define_attribute_methods [ name ]
  self
end

#attribute_namesObject



215
216
217
# File 'lib/rubyhaze/persisted/model.rb', line 215

def attribute_names()
  attributes.map { |ary| ary[0] }
end

#attribute_optionsObject



223
224
225
# File 'lib/rubyhaze/persisted/model.rb', line 223

def attribute_options()
  attributes.map { |ary| ary[2] }
end

#attribute_typesObject



219
220
221
# File 'lib/rubyhaze/persisted/model.rb', line 219

def attribute_types()
  attributes.map { |ary| ary[1] }
end

#attributesObject



211
212
213
# File 'lib/rubyhaze/persisted/model.rb', line 211

def attributes
  @attributes ||= [[:uid, :string, {}]]
end

#create(options = {}) ⇒ Object



197
198
199
200
201
# File 'lib/rubyhaze/persisted/model.rb', line 197

def create(options = {})
  obj = new options
  obj.save
  obj
end

#find(predicate) ⇒ Object



235
236
237
# File 'lib/rubyhaze/persisted/model.rb', line 235

def find(predicate)
  map.values(predicate).map { |shadow| new.load_shadow_object shadow }
end

#find_uids(predicate) ⇒ Object



245
246
247
# File 'lib/rubyhaze/persisted/model.rb', line 245

def find_uids(predicate)
  map.keys(predicate)
end

#mapObject



207
208
209
# File 'lib/rubyhaze/persisted/model.rb', line 207

def map
  @map ||= RubyHaze::Map.new "RubyHaze::Persisted #{name}"
end

#map_java_classObject



203
204
205
# File 'lib/rubyhaze/persisted/model.rb', line 203

def map_java_class
  @java_class ||= RubyHaze::Persisted::Shadow::Generator.get name, attributes
end