Class: Titanium::Resource
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .count_by_name(name) ⇒ Object
- .delete_all_by_name(name) ⇒ Object
- .find_by_name(name, sort_field = nil, sort_order = nil, limit = nil, offset = nil) ⇒ Object
- .find_by_name_and_key(name, key) ⇒ Object
- .find_by_name_and_params(name, params, sort_field = nil, sort_order = nil, limit = nil, offset = nil) ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(name, options = {}) ⇒ Resource
constructor
Constructs a new Resource.
- #insert ⇒ Object
- #to_json ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Resource
31 32 33 34 35 |
# File 'lib/resource.rb', line 31 def initialize(name, ={}) @name = name @key = [:key] @metadata = [:metadata] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
24 25 26 |
# File 'lib/resource.rb', line 24 def key @key end |
#metadata ⇒ Object
Returns the value of attribute metadata.
25 26 27 |
# File 'lib/resource.rb', line 25 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/resource.rb', line 24 def name @name end |
Class Method Details
.count_by_name(name) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resource.rb', line 89 def self.count_by_name(name) db_instance = Configuration.db_adapter.new begin db_instance.connect count = db_instance.count_by_name(name) return count ensure db_instance.disconnect end end |
.delete_all_by_name(name) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/resource.rb', line 100 def self.delete_all_by_name(name) db_instance = Configuration.db_adapter.new begin db_instance.connect return db_instance.delete_all_by_name(name) ensure db_instance.disconnect end end |
.find_by_name(name, sort_field = nil, sort_order = nil, limit = nil, offset = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/resource.rb', line 73 def self.find_by_name(name, sort_field=nil, sort_order=nil, limit=nil, offset=nil) db_instance = Configuration.db_adapter.new begin db_instance.connect resources = [] result = db_instance.find_by_name_and_conditions(name, nil, nil, sort_field, sort_order, limit, offset) result.each do |row| key = row.delete('key') resources << Resource.new(name, {:key => key, :metadata => row}) end return resources ensure db_instance.disconnect end end |
.find_by_name_and_key(name, key) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/resource.rb', line 110 def self.find_by_name_and_key(name, key) db_instance = Configuration.db_adapter.new begin db_instance.connect resources = [] result = db_instance.find_by_name_and_conditions(name, key) result.each do |row| key = row.delete('key') resources << Resource.new(name, {:key => key, :metadata => row}) end return resources ensure db_instance.disconnect end end |
.find_by_name_and_params(name, params, sort_field = nil, sort_order = nil, limit = nil, offset = nil) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/resource.rb', line 126 def self.find_by_name_and_params(name, params, sort_field=nil, sort_order=nil, limit=nil, offset=nil) db_instance = Configuration.db_adapter.new begin db_instance.connect resources = [] result = db_instance.find_by_name_and_conditions(name, nil, params, sort_field, sort_order, limit, offset) result.each do |row| key = row.delete('key') resources << Resource.new(name, {:key => key, :metadata => row}) end return resources ensure db_instance.disconnect end end |
Instance Method Details
#delete ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/resource.rb', line 63 def delete db_instance = Configuration.db_adapter.new begin db_instance.connect return db_instance.delete(@key) ensure db_instance.disconnect end end |
#insert ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/resource.rb', line 43 def insert db_instance = Configuration.db_adapter.new begin db_instance.connect return db_instance.insert(@name, @metadata) ensure db_instance.disconnect end end |
#to_json ⇒ Object
37 38 39 40 41 |
# File 'lib/resource.rb', line 37 def to_json json_hash = @metadata.dup json_hash[:key] = @key json_hash.to_json end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/resource.rb', line 53 def update db_instance = Configuration.db_adapter.new begin db_instance.connect return db_instance.update(@key, @metadata) ensure db_instance.disconnect end end |