Dagnabit C0 Coverage Information - RCov

lib/dagnabit/link/transitive_closure_link_model.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/dagnabit/link/transitive_closure_link_model.rb 86 25
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module Dagnabit
2   module Link
3     #
4     # Builds a model for transitive closure tuples.
5     #
6     # The transitive closure model is generated inside the link class.
7     # Therefore, if your link model class was called Link, the transitive
8     # closure model would be named Link::(class name here).  The name of the
9     # transitive closure model class is determined when the link class model is
10     # activated; see Dagnabit::Activation#acts_as_dag_link for more information.
11     #
12     # == Model class details
13     # 
14     # === Construction details
15     #
16     # The transitive closure model is constructed as a subclass of
17     # ActiveRecord::Base, _not_ as a subclass of your link model class.  The
18     # transitive closure model also acts as a dag link (via
19     # Dagnabit::Activation#acts_as_dag_link) and is configured using the same
20     # configuration options as your link model class.
21     #
22     # This means:
23     #
24     # * The transitive closure tuple table and your link table must have the
25     #   same column names for ancestor id/type and descendant id/type.
26     # * You will not be able to use any methods defined on your link model on
27     #   the transitive closure model.
28     #
29     # === Available methods
30     #
31     # The following class methods are available on transitive closure link
32     # models:
33     #
34     # [linking(a, b)]
35     #   Returns all links (direct or indirect) linking +a+ and +b+.  
36     # [ancestor_type(type)]
37     #   Behaves identically to the ancestor_type named scope defined in
38     #   Dagnabit::Link::NamedScopes.
39     # [descendant_type(type)]
40     #   Behaves identically to the descendant_type named scope defined in
41     #   Dagnabit::Link::NamedScopes.
42     #
43     # The following instance methods are available on transitive closure link
44     # models:
45     #
46     # [ancestor]
47     #   Returns the ancestor of this link.  Behaves identically to the
48     #   ancestor association defined in Dagnabit::Link::Associations.
49     # [descendant]
50     #   Returns the descendant of this link.  Behaves identically to the
51     #   descendant association defined in Dagnabit::Link::Associations.
52     #
53     module TransitiveClosureLinkModel
54       attr_reader :transitive_closure_class
55 
56       private
57 
58       #
59       # Generates the transitive closure model.
60       #
61       def generate_transitive_closure_link_model(options)
62         original_class = self
63 
64         klass = Class.new(ActiveRecord::Base) do
65           extend Dagnabit::Link::Configuration
66 
67           configure_acts_as_dag_link(options)
68           set_table_name original_class.unquoted_transitive_closure_table_name
69         end
70 
71         @transitive_closure_class = const_set(transitive_closure_class_name, klass)
72 
73         # reflections and named scopes aren't properly created in anonymous
74         # models, so we need to do that work after the model has been named
75         @transitive_closure_class.extend(Dagnabit::Link::Associations)
76         @transitive_closure_class.extend(Dagnabit::Link::NamedScopes)
77         @transitive_closure_class.named_scope :linking, lambda { |from, to|
78             { :conditions => { ancestor_id_column => from.id,
79                                ancestor_type_column => from.class.name,
80                                descendant_id_column => to.id,
81                                descendant_type_column => to.class.name } }
82         }
83       end
84     end
85   end
86 end

Generated on Tue Dec 08 04:06:14 -0600 2009 with rcov 0.9.6