Module: CouchRest::Commands::Push

Defined in:
lib/couchrest/commands/push.rb

Class Method Summary collapse

Class Method Details

.helpObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/couchrest/commands/push.rb', line 21

def self.help
  helpstring = "\n  == Pushing views with Couchview ==\n\n  Usage: couchview push directory dbname\n\n  Couchview expects a specific filesystem layout for your CouchDB views (see\n  example below). It also supports advanced features like inlining of library\n  code (so you can keep DRY) as well as avoiding unnecessary document\n  modification.\n\n  Couchview also solves a problem with CouchDB's view API, which only provides\n  access to the final reduce side of any views which have both a map and a\n  reduce function defined. The intermediate map results are often useful for\n  development and production. CouchDB is smart enough to reuse map indexes for\n  functions duplicated across views within the same design document.\n\n  For views with a reduce function defined, Couchview creates both a reduce view\n  and a map-only view, so that you can browse and query the map side as well as\n  the reduction, with no performance penalty.\n\n  == Example ==\n\n  couchview push foo-project/bar-views baz-database\n\n  This will push the views defined in foo-project/bar-views into a database\n  called baz-database. Couchview expects the views to be defined in files with\n  names like:\n\n  foo-project/bar-views/my-design/viewname-map.js\n  foo-project/bar-views/my-design/viewname-reduce.js\n  foo-project/bar-views/my-design/noreduce-map.js\n\n  Pushed to => http://127.0.0.1:5984/baz-database/_design/my-design\n\n  And the design document:\n  {\n    \"views\" : {\n      \"viewname-map\" : {\n        \"map\" : \"### contents of view-name-map.js ###\"\n      },\n      \"viewname-reduce\" : {\n        \"map\" : \"### contents of view-name-map.js ###\",\n        \"reduce\" : \"### contents of view-name-reduce.js ###\"\n      },\n      \"noreduce-map\" : {\n        \"map\" : \"### contents of noreduce-map.js ###\"\n      }\n    }\n  }\n\n  Couchview will create a design document for each subdirectory of the views\n  directory specified on the command line.\n\n  == Library Inlining ==\n\n  Couchview can optionally inline library code into your views so you only have\n  to maintain it in one place. It looks for any files named lib.* in your\n  design-doc directory (for doc specific libs) and in the parent views directory\n  (for project global libs). These libraries are only inserted into views which\n  include the text\n\n  // !include lib\n\n  or\n\n  # !include lib\n\n  Couchview is a result of scratching my own itch. I'd be happy to make it more\n  general, so please contact me at [email protected] if you'd like to see anything\n  added or changed.\n\n  GEN\n  helpstring.gsub(/^        /, '')\nend\n"

.run(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/couchrest/commands/push.rb', line 7

def self.run(options)
  directory = options[:directory]
  database  = options[:trailing_args].first

  fm      = CouchRest::FileManager.new(database)
  fm.loud = options[:loud]

  if options[:loud]
    puts "Pushing views from directory #{directory} to database #{fm.db}"
  end

  fm.push_views(directory)
end