Class: ActiveCouch::View
- Inherits:
-
Object
- Object
- ActiveCouch::View
- Defined in:
- lib/active_couch/views/view.rb
Class Attribute Summary collapse
-
.database ⇒ Object
These are accessible only at class-scope.
-
.name ⇒ Object
These are accessible only at class-scope.
Class Method Summary collapse
-
.define(*args) ⇒ Object
Set the view name and database name in the define method and then execute the block.
- .include_attributes(*attrs) ⇒ Object
- .to_json(existing_view = {}) ⇒ Object
- .with_filter(filter = "") ⇒ Object
- .with_key(key = "") ⇒ Object
Class Attribute Details
.database ⇒ Object
These are accessible only at class-scope
9 10 11 |
# File 'lib/active_couch/views/view.rb', line 9 def database @database end |
.name ⇒ Object
These are accessible only at class-scope
9 10 11 |
# File 'lib/active_couch/views/view.rb', line 9 def name @name end |
Class Method Details
.define(*args) ⇒ Object
Set the view name and database name in the define method and then execute the block
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_couch/views/view.rb', line 12 def define(*args) # Borrowed from ActiveRecord::Base.find first = args.slice!(0); second = args.slice!(0) # Based on the classes of the arguments passed, set instance variables case first.class.to_s when 'String', 'Symbol' then name = first.to_s; = second || {} when 'Hash' then name = ''; = first else raise ArgumentError, "Wrong arguments used to define the view" end # Define the view and database instance variables based on the args passed # Don't care if the key doesn't exist @name, @database = get_name(name), [:for_db] # Block being called to set other parameters for the Migration yield if block_given? end |
.include_attributes(*attrs) ⇒ Object
36 37 38 |
# File 'lib/active_couch/views/view.rb', line 36 def include_attributes(*attrs) @attrs = attrs unless attrs.nil? || !attrs.is_a?(Array) end |
.to_json(existing_view = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/active_couch/views/view.rb', line 40 def to_json(existing_view = {}) results_hash = { "_id" => "_design/#{@name}", "language" => view_language } results_hash.merge!(existing_view) results_hash['views'] = view_function # Returns the JSON format for the function results_hash.to_json end |
.with_filter(filter = "") ⇒ Object
32 33 34 |
# File 'lib/active_couch/views/view.rb', line 32 def with_filter(filter = "") @filter = filter unless filter.nil? end |
.with_key(key = "") ⇒ Object
28 29 30 |
# File 'lib/active_couch/views/view.rb', line 28 def with_key(key = "") @key = key unless key.nil? end |