Skip to content

Commit

Permalink
added View.define("name") syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Andreev committed Apr 28, 2008
1 parent 2ee09a0 commit 289e433
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/strokedb/views/view.rb
Expand Up @@ -229,13 +229,21 @@ def [](name)
# TODO: find viewdoc by name
end

def define(options = {}, &block)
# Define a view.
#
# Examples
# View.define("view_name", :option => "value") do |viewdoc| ... end
# View.define(:name => "view_name", :option => "value") do |viewdoc| ... end
#
def define(*args, &block)
options = args.pop.stringify_keys rescue { }
# TODO: find the view through the Views' view.
name = options.stringify_keys['name']
name = options['name'] || args.pop
unless name
raise ArgumentError, "View name must be specified!"
end
find_or_create(:name => name) do |view|
# FIXME: we must save a new version when options update a viewdoc contents
view.update_slots(options)
block.call(view) if block
end
Expand Down

0 comments on commit 289e433

Please sign in to comment.