Class: Buhos::DBAdapter
- Inherits:
-
Object
- Object
- Buhos::DBAdapter
- Defined in:
- lib/buhos/dbadapter.rb
Overview
Delegation pattern for Sequel::Database Used on spec to change the database between tests
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.method_missing(m, *args, &block) ⇒ Object
puts “There’s no method called #m here – please try again.”.
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize ⇒ DBAdapter
constructor
A new instance of DBAdapter.
- #method_missing(m, *args, &block) ⇒ Object
-
#update_model_association ⇒ Object
This is ugly.
- #use_db(db) ⇒ Object
Constructor Details
#initialize ⇒ DBAdapter
Returns a new instance of DBAdapter.
35 36 37 |
# File 'lib/buhos/dbadapter.rb', line 35 def initialize @current=nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
116 117 118 119 120 |
# File 'lib/buhos/dbadapter.rb', line 116 def method_missing(m, *args, &block) #puts "#{m}: #{args}" @current.send(m, *args, &block) #puts "There's no method called #{m} here -- please try again." end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
34 35 36 |
# File 'lib/buhos/dbadapter.rb', line 34 def logger @logger end |
Class Method Details
.method_missing(m, *args, &block) ⇒ Object
puts “There’s no method called #m here – please try again.”
121 122 123 |
# File 'lib/buhos/dbadapter.rb', line 121 def self.method_missing(m, *args, &block) raise "Can't handle this" end |
Instance Method Details
#current ⇒ Object
38 39 40 |
# File 'lib/buhos/dbadapter.rb', line 38 def current @current end |
#update_model_association ⇒ Object
This is ugly. I know. I just do it to allow testing
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/buhos/dbadapter.rb', line 47 def update_model_association ::IFile.dataset=self[:files] ::FileCd.dataset=self[:file_cds] ::FileSr.dataset=self[:file_srs] ::AllocationCd.dataset=self[:allocation_cds] ::BibliographicDatabase.dataset=self[:bibliographic_databases] ::Search.dataset=self[:searches] ::CanonicalDocument.dataset=self[:canonical_documents] ::CrossrefDoi.dataset=self[:crossref_dois] ::CrossrefQuery.dataset=self[:crossref_queries] ::Decision.dataset=self[:decisions] ::Group.dataset=self[:groups] ::Message.dataset=self[:messages] ::MessageSr.dataset=self[:message_srs] ::MessageSrSeen.dataset=self[:message_sr_seens] ::Reference.dataset=self[:bib_references] ::RecordsReferences.dataset=self[:records_references] ::Resolution.dataset=self[:resolutions] ::Record.dataset=self[:records] ::RecordsSearch.dataset=self[:records_searches] ::Tag.dataset=self[:tags] ::T_Class.dataset=self[:t_classes] ::TagInClass.dataset=self[:tag_in_classes] ::TagInCd.dataset=self[:tag_in_cds] ::TagBwCd.dataset=self[:tag_bw_cds] ::SystematicReview.dataset=self[:systematic_reviews] ::SrField.dataset=self[:sr_fields] ::SrTaxonomy.dataset=self[:sr_taxonomies] ::SrTaxonomyCategory.dataset=self[:sr_taxonomy_categories] ::Systematic_Review_SRTC.dataset=self[:systematic_review_srtcs] ::User.dataset=self[:users] ::Authorization.dataset=self[:authorizations] ::Role.dataset=self[:roles] ::Scopus_Abstract.dataset=self[:scopus_abstracts] ::Group.dataset=self[:groups] ::GroupsUser.dataset=self[:groups_users] ::AuthorizationsRole.dataset=self[:authorizations_roles] ::Criterion.dataset=self[:criteria] ::SrCriterion.dataset=self[:sr_criteria] ::CdCriterion.dataset=self[:cd_criteria] ::Criterion.dataset=self[:criteria] ::QualityCriterion.dataset=self[:quality_criteria] ::SrQualityCriterion.dataset=self[:sr_quality_criteria] ::CdQualityCriterion.dataset=self[:cd_quality_criteria] ::Scale.dataset=self[:scales] ::Pmc_Summary.dataset=self[:pmc_summaries] ::Search.many_to_many :records, :class=>Record ::Record.many_to_one :canonical_document, :class=>CanonicalDocument ::Reference.many_to_many :records ::SystematicReview.many_to_one :group ::SystematicReview.one_to_many :message_srs, :class=>MessageSr ::QualityCriterion ::Group.many_to_many :users end |
#use_db(db) ⇒ Object
41 42 43 44 |
# File 'lib/buhos/dbadapter.rb', line 41 def use_db(db) @current=db db.loggers << @logger end |