Sha256: cd4d7fa77c40e391fb16e2d4af1c2ae91657a3a240c1d92280ed74bdd88e1ede

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

#
# Copyright (C) 2009  Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


class BaseModel

  def initialize(init=nil)
    if ( init )
      @id=init[:id]
      init.each{|k,v|
        self.send( "#{k}=", v ) if ( self.respond_to?( "#{k}=" ) )
      }
    end
  end

  def self.attr_accessor(*vars)
    @attributes ||= [:id]
    @attributes.concat vars
    super
  end

  def self.attributes
    @attributes
  end

  def attributes
    self.class.attributes
  end

  def id
    @id
  end

  def to_hash
    out = {}
    self.attributes.each { |attribute| out.merge!({ attribute => self.send(:"#{attribute}") } ) }
    out
  end

  def to_json
    self.to_hash.to_json
  end

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
bbrowning-deltacloud-core-0.0.1.1 lib/deltacloud/models/base_model.rb
deltacloud-core-0.0.2 lib/deltacloud/models/base_model.rb
deltacloud-core-0.0.1 lib/deltacloud/models/base_model.rb