class ActiveGist::Files

Attributes

hash[R]

Public Class Methods

new(hash = {}) click to toggle source
# File lib/active_gist/files.rb, line 6
def initialize(hash = {})
  @hash = hash
  @changed = false
end

Public Instance Methods

changed?() click to toggle source
# File lib/active_gist/files.rb, line 11
def changed?
  @hash_copy != hash
end
method_missing(name, *args, &block) click to toggle source
# File lib/active_gist/files.rb, line 22
def method_missing(name, *args, &block)
  hash.send name, *args, &block
end
replace_with(hash) click to toggle source
# File lib/active_gist/files.rb, line 15
def replace_with(hash)
  return hash if hash == @hash
  @changed = true
  @hash_copy = deep_dup hash
  @hash = hash
end

Private Instance Methods

deep_dup(obj) click to toggle source
# File lib/active_gist/files.rb, line 27
def deep_dup(obj)
  if obj.kind_of?(Array)
    obj.collect { |a| deep_dup a }
  elsif obj.kind_of?(Hash)
    obj.inject(HashWithIndifferentAccess.new) { |h,(k,v)| h[deep_dup(k)] = deep_dup(v); h }
  elsif obj.respond_to?(:dup)
    begin
      obj.dup
    rescue TypeError
      obj
    end
  else
    obj
  end
end