Module: RubyHaze::Persisted::ClassMethods
- Defined in:
- lib/rubyhaze/persisted/model.rb
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #attribute(name, type, options = {}) ⇒ Object
- #attribute_names ⇒ Object
- #attribute_options ⇒ Object
- #attribute_types ⇒ Object
- #attributes ⇒ Object
- #create(options = {}) ⇒ Object
- #find(predicate) ⇒ Object
- #find_uids(predicate) ⇒ Object
- #map ⇒ Object
- #map_java_class ⇒ Object
Instance Method Details
#[](*args) ⇒ Object
239 240 241 242 243 |
# File 'lib/rubyhaze/persisted/model.rb', line 239 def [](*args) = args. [:uid] = args.first if RubyHaze.valid_uuid?(args.first) find().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, = {}) raise "Attribute [#{name}] already defined" if attribute_names.include?(name) @attributes << [name, type, ] @attribute_methods_generated = false define_attribute_methods [ name ] self end |
#attribute_names ⇒ Object
215 216 217 |
# File 'lib/rubyhaze/persisted/model.rb', line 215 def attribute_names() attributes.map { |ary| ary[0] } end |
#attribute_options ⇒ Object
223 224 225 |
# File 'lib/rubyhaze/persisted/model.rb', line 223 def () attributes.map { |ary| ary[2] } end |
#attribute_types ⇒ Object
219 220 221 |
# File 'lib/rubyhaze/persisted/model.rb', line 219 def attribute_types() attributes.map { |ary| ary[1] } end |
#attributes ⇒ Object
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( = {}) obj = new 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 |
#map ⇒ Object
207 208 209 |
# File 'lib/rubyhaze/persisted/model.rb', line 207 def map @map ||= RubyHaze::Map.new "RubyHaze::Persisted #{name}" end |
#map_java_class ⇒ Object
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 |