Sha256: 4aa6c484dce706f247c7324877414e20d1b82529712682e8fda84573cb3912bf

Contents?: true

Size: 854 Bytes

Versions: 12

Compression:

Stored size: 854 Bytes

Contents

module Makura
  class Design
    attr_accessor :database, :name, :language
    attr_reader :layouts

    def initialize(name, database = nil)
      @name, @database = name, database
      @language = 'javascript'
      @layouts = {}
    end

    def save
      hash = to_hash
      doc = @database[hash['_id']]
      doc['views'] = hash['views']
      @database.save(doc)
    rescue Makura::Error::ResourceNotFound
      @database.save(to_hash)
    end

    def [](layout_name)
      @layouts[layout_name.to_s]
    end

    def []=(layout_name, layout)
      @layouts[layout_name.to_s] = layout
    end

    def to_hash
      views = {}
      @layouts.each{|name, layout| views[name] = layout.to_hash }
      views.delete_if{|k,v| !(v[:map] || v['map']) }

      {'language' => @language, '_id' => "_design/#{@name}", 'views' => views}
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
careo-makura-0.1 lib/makura/design.rb
careo-makura-2009.2.17 lib/makura/design.rb
manveru-makura-2009.02.18 lib/makura/design.rb
manveru-makura-2009.03.01 lib/makura/design.rb
manveru-makura-2009.03.28 lib/makura/design.rb
manveru-makura-2009.04.22 lib/makura/design.rb
manveru-makura-2009.05.27 lib/makura/design.rb
makura-2012.01 lib/makura/design.rb
makura-2011.01.21 lib/makura/design.rb
makura-2010.08.26 lib/makura/design.rb
makura-2010.08 lib/makura/design.rb
makura-2009.05.27 lib/makura/design.rb