Class: CouchView::Config
- Inherits:
-
Object
- Object
- CouchView::Config
- Defined in:
- lib/couch_view/config.rb,
lib/couch_view/conditions.rb
Defined Under Namespace
Classes: Conditions
Instance Attribute Summary collapse
-
#conditions(*args, &block) ⇒ Object
readonly
Returns the value of attribute conditions.
-
#map_class ⇒ Object
readonly
Returns the value of attribute map_class.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #base_view_name(name = nil) ⇒ Object
- #conditions_config ⇒ Object
-
#initialize(model_class) ⇒ Config
constructor
A new instance of Config.
- #map(*args, &block) ⇒ Object
- #reduce(function = nil) ⇒ Object
- #view_names ⇒ Object
- #views ⇒ Object
Constructor Details
#initialize(model_class) ⇒ Config
Returns a new instance of Config.
5 6 7 8 |
# File 'lib/couch_view/config.rb', line 5 def initialize(model_class) @model = model_class @conditions = CouchView::Config::Conditions.new end |
Instance Attribute Details
#conditions(*args, &block) ⇒ Object (readonly)
Returns the value of attribute conditions.
3 4 5 |
# File 'lib/couch_view/config.rb', line 3 def conditions @conditions end |
#map_class ⇒ Object (readonly)
Returns the value of attribute map_class.
3 4 5 |
# File 'lib/couch_view/config.rb', line 3 def map_class @map_class end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/couch_view/config.rb', line 3 def model @model end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
3 4 5 |
# File 'lib/couch_view/config.rb', line 3 def properties @properties end |
Instance Method Details
#base_view_name(name = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/couch_view/config.rb', line 50 def base_view_name(name=nil) if name @base_view_name = name elsif @base_view_name @base_view_name elsif @properties.empty? @base_view_name = @map_class.to_s.underscore else @base_view_name = "by_" + @properties.map(&:to_s).map(&:underscore).join("_and_") end end |
#conditions_config ⇒ Object
23 24 25 |
# File 'lib/couch_view/config.rb', line 23 def conditions_config @conditions end |
#map(*args, &block) ⇒ Object
10 11 12 13 |
# File 'lib/couch_view/config.rb', line 10 def map(*args, &block) @map_class, @properties = extract_map_class_data args self.instance_eval &block if block end |
#reduce(function = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/couch_view/config.rb', line 15 def reduce(function=nil) if function @reduce = function else @reduce ||= "_count" end end |
#view_names ⇒ Object
36 37 38 |
# File 'lib/couch_view/config.rb', line 36 def view_names views.keys.map &:to_s end |
#views ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/couch_view/config.rb', line 40 def views all_views = {} all_views[base_view_name.to_sym] = { :map => @map_class.new(@model, *@properties).map, :reduce => reduce } all_views.merge! condition_views all_views end |