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)
-
- (Object) conditions(*args, &block)
readonly
Returns the value of attribute conditions.
-
- (Object) map_class
readonly
Returns the value of attribute map_class.
-
- (Object) model
readonly
Returns the value of attribute model.
-
- (Object) properties
readonly
Returns the value of attribute properties.
Instance Method Summary (collapse)
- - (Object) base_view_name(name = nil)
- - (Object) conditions_config
-
- (Config) initialize(model_class)
constructor
A new instance of Config.
- - (Object) map(*args, &block)
- - (Object) reduce(function = nil)
- - (Object) view_names
- - (Object) views
Constructor Details
- (Config) initialize(model_class)
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
- (Object) conditions(*args, &block) (readonly)
Returns the value of attribute conditions
3 4 5 6 7 8 9 10 |
# File 'lib/couch_view/config.rb', line 3 def conditions(*args, &block) if args.empty? && block.nil? @conditions.conditions else @conditions.add_conditions *args @conditions.instance_eval &block if block end end |
- (Object) map_class (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 |
- (Object) model (readonly)
Returns the value of attribute model
3 4 5 |
# File 'lib/couch_view/config.rb', line 3 def model @model end |
- (Object) properties (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
- (Object) base_view_name(name = nil)
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 |
- (Object) conditions_config
23 24 25 |
# File 'lib/couch_view/config.rb', line 23 def conditions_config @conditions end |
- (Object) map(*args, &block)
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 |
- (Object) reduce(function = nil)
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 |
- (Object) view_names
36 37 38 |
# File 'lib/couch_view/config.rb', line 36 def view_names views.keys.map &:to_s end |
- (Object) views
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 |