mirror of
https://github.com/mistergibson/gxg-framework.git
synced 2026-08-15 03:46:00 -07:00
added persist to Array/Hash and added merge to Detached/Persisted
This commit is contained in:
parent
5a08aa52eb
commit
1bd8e8fb41
4 changed files with 120 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'gxg-framework'
|
s.name = 'gxg-framework'
|
||||||
s.version = '0.0.67'
|
s.version = '0.0.68'
|
||||||
s.licenses = ['HIPPOCRATIC 2.1', 'https://firstdonoharm.dev/version/2/1/license.html']
|
s.licenses = ['HIPPOCRATIC 2.1', 'https://firstdonoharm.dev/version/2/1/license.html']
|
||||||
s.summary = "GxG Framework"
|
s.summary = "GxG Framework"
|
||||||
s.description = "GxG Framework"
|
s.description = "GxG Framework"
|
||||||
|
|
|
||||||
|
|
@ -3772,7 +3772,6 @@ class Hash
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
#
|
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
class Array
|
class Array
|
||||||
|
|
@ -4149,6 +4148,11 @@ class Array
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# OpenStruct support for Arrays.
|
# OpenStruct support for Arrays.
|
||||||
module GxG
|
module GxG
|
||||||
class ArrayWrapper
|
class ArrayWrapper
|
||||||
|
|
|
||||||
|
|
@ -5504,3 +5504,28 @@ end
|
||||||
require File.expand_path("./gxg_database_persistedarray.rb",File.dirname(__FILE__))
|
require File.expand_path("./gxg_database_persistedarray.rb",File.dirname(__FILE__))
|
||||||
require File.expand_path("./gxg_database_persistedhash.rb",File.dirname(__FILE__))
|
require File.expand_path("./gxg_database_persistedhash.rb",File.dirname(__FILE__))
|
||||||
#
|
#
|
||||||
|
class Hash
|
||||||
|
#
|
||||||
|
def persist(credential=::GxG::DB[:administrator], to_db=:data)
|
||||||
|
result = nil
|
||||||
|
database = ::GxG::DB[:roles][(to_db)]
|
||||||
|
if database.is_a?(::GxG::Database::Database)
|
||||||
|
result = database.try_persist(self, credential)
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
#
|
||||||
|
class Array
|
||||||
|
#
|
||||||
|
def persist(credential=::GxG::DB[:administrator], to_db=:data)
|
||||||
|
result = nil
|
||||||
|
database = ::GxG::DB[:roles][(to_db)]
|
||||||
|
if database.is_a?(::GxG::Database::Database)
|
||||||
|
result = database.try_persist(self, credential)
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -965,6 +965,50 @@ module GxG
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
def merge!(input_object=nil, options={})
|
||||||
|
result = self
|
||||||
|
if input_object.is_any?(::Hash, ::GxG::Database::DetachedHash, ::GxG::Database::PersistedHash)
|
||||||
|
#
|
||||||
|
if @format
|
||||||
|
# merge only keys common to both
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
if result.keys.include?(import_key)
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def merge(input_object=nil, options={})
|
||||||
|
result = self
|
||||||
|
if input_object.is_any?(::Hash, ::GxG::Database::DetachedHash, ::GxG::Database::PersistedHash)
|
||||||
|
result = ::GxG::Database::DetachedHash::iterative_detached_persist(self.unpersist)
|
||||||
|
#
|
||||||
|
if @format
|
||||||
|
# merge only keys common to both
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
if result.keys.include?(import_key)
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
result.format = @format
|
||||||
|
else
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
class PersistedHash
|
class PersistedHash
|
||||||
|
|
@ -2849,6 +2893,51 @@ module GxG
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
def merge!(input_object=nil, options={})
|
||||||
|
result = self
|
||||||
|
if input_object.is_any?(::Hash, ::GxG::Database::DetachedHash, ::GxG::Database::PersistedHash)
|
||||||
|
#
|
||||||
|
if @format
|
||||||
|
# merge only keys common to both
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
if result.keys.include?(import_key)
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def merge(input_object=nil, options={})
|
||||||
|
result = self
|
||||||
|
if input_object.is_any?(::Hash, ::GxG::Database::DetachedHash, ::GxG::Database::PersistedHash)
|
||||||
|
#
|
||||||
|
result = ::GxG::Database::DetachedHash::iterative_detached_persist(self.unpersist)
|
||||||
|
#
|
||||||
|
if @format
|
||||||
|
# merge only keys common to both
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
if self.keys.include?(import_key)
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
result.format = @format
|
||||||
|
else
|
||||||
|
input_object.keys.each do |import_key|
|
||||||
|
result[(import_key)] = input_object[(import_key)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue