Sha256: e50600429db1a7023fda85d80029baf37320c723af7006987971318a77ba9b73

Contents?: true

Size: 817 Bytes

Versions: 3

Compression:

Stored size: 817 Bytes

Contents

module Plaza
  module BaseModel
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      ## assumes a shallow hierarchy where there is only one
      ## root element that contains an array of hashes
      ## For Example:
      ## {:campaign_ranks=>[{:key=>1, :rank=>"0.4"}, {:key=>2, :rank=>"0.9"}]}
      def collection(response)
        response.values.first.collect do |obj|
          self.new(obj)
        end
      end

      def adapter
        Plaza.adapter(self)
      end

    end

    def adapter
      self.class.adapter
    end

    def singular_name
      self.class.to_s.split('::').last.scan(/[A-Z][a-z]+/).join('_').downcase
    end

    def serialize
      {singular_name => attributes}
    end

    def to_json
      self.serialize.to_json
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plaza-0.1.1 lib/plaza/models/base_model.rb
plaza-0.1.0 lib/plaza/models/base_model.rb
plaza-0.0.4 lib/plaza/models/base_model.rb