Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cutting over rails3 to master.

This switches the Metasploit Framework to a Rails 3 backend. If you run
into new problems (especially around Active Record or your postgresql
gem) you should try first updating your Ruby installation to 1.9.3 and
use a more recent 'pg' gem.

If that fails, we'd love to see your bug report (just drop all the
detail you can into an issue on GitHub). In the meantime, you can
checkout the rails2 branch, which was branched from master immediately
before this cutover.

Squashed commit of the following:

commit 5802ec8
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 23:30:12 2012 -0500

    Enable MSF_BUNDLE_GEMS mode by default (set to N/F/0 to disable)

commit 8102f98
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 23:30:03 2012 -0500

    Add a method to expand win32 file paths

commit bda6479
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:53:44 2012 -0500

    Fix 1.8.x compatibility

commit 101ce4e
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:40:59 2012 -0500

    Use verbose instead of stringio

commit 5db467f
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:30:06 2012 -0500

    Hide the iconv warning, were stuck with it due to EBCDIC support

commit 63b9cb2
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:29:58 2012 -0500

    Dont use GEM_HOME by default

commit ca49271
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:23:34 2012 -0500

    Move Gemfile to root (there be dragons, lets find them) and catch failed bundler loads

commit 34af040
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 18:18:29 2012 -0500

    Fallback to bundler when not running inside of a installer env

commit ed1066a
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 16:26:55 2012 -0500

    Remove a mess of gems that were not actually required

commit 21290a7
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 15:59:10 2012 -0500

    Hack around a gem() call that is well-intentioned but an obstacle in this case

commit 8e414a8
Author: Tod Beardsley <todb@metasploit.com>
Date:   Sun Apr 15 15:06:08 2012 -0500

    Ruby, come on. Ducktype this. Please.

    Use interpolated strings to get the to_s behavior you don't get with
    just plussing.

commit 0fa92c5
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 15:05:42 2012 -0500

    Add new eventmachine/thin gems

commit 819d5e7
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 15:01:18 2012 -0500

    Purge (reimport in a second)

commit ea6f3f6
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 14:54:42 2012 -0500

    Cleanup uncessary .so files (ext vs lib)

commit d219330
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 14:53:02 2012 -0500

    PG gems built against the older installation environment

commit d6e590c
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 14:06:35 2012 -0500

    Rename to include the version

commit a893de2
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 13:56:47 2012 -0500

    Detect older installation environments and load the arch-lib directories into the search path

commit 6444bba
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 13:49:25 2012 -0500

    Merge in windows gems

commit 95efbcf
Author: Tod Beardsley <todb@metasploit.com>
Date:   Sun Apr 15 13:49:33 2012 -0500

    Report_vuln shouldn't use :include in finder

    find_or_create_by doesn't take :include as a param.

commit c5f99eb
Author: David Maloney <DMaloney@rapid7.com>
Date:   Sun Apr 15 12:44:09 2012 -0500

    One more msised Mdm namespace issue

commit 2184e2b
Author: David Maloney <DMaloney@rapid7.com>
Date:   Sun Apr 15 12:33:41 2012 -0500

    Fixes some mroe Mdm namespace confusion
    Fixes #6626

commit 10cee17
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 03:40:44 2012 -0500

    Add robots gem (required by webscan)

commit 327e674
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 03:39:05 2012 -0500

    Fix missing error checks

commit a5a2464
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 01:15:37 2012 -0500

    Reorder requires and add a method for injecting a new migration path

commit 250a5fa
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 00:56:09 2012 -0500

    Remove missing constant (use string) and add gemcache cleaner

commit 37ad606
Merge: d47ee82 4be0361
Author: Tod Beardsley <todb@metasploit.com>
Date:   Sun Apr 15 00:40:16 2012 -0500

    Merge branch 'master-clone' into rails3-clone

commit d47ee82
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 00:30:03 2012 -0500

    cleanup leftovers from gems

commit 6d883b5
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sun Apr 15 00:25:47 2012 -0500

    MDM update with purged DBSave module

commit 71e4f2d
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 23:19:37 2012 -0500

    Add new mdm

commit 651cd5a
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 23:19:13 2012 -0500

    Update mdm

commit 0191a8b
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 22:30:40 2012 -0500

    This fixes numerous cases of missed Mdm:: prefixes on db objects

commit a2a9bb3
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 18:30:18 2012 -0500

    Add eventmachine

commit 301ddeb
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 18:18:12 2012 -0500

    A nicer error for folks who need to upgrade pg

commit fa6bde1
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 17:54:55 2012 -0500

    Remove bundler requirements

commit 2e3ab9e
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 17:35:38 2012 -0500

    Pull in eventmachine with actual .so's this time

commit 901fb33
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 17:19:12 2012 -0500

    Update deps, still need to add eventmachine

commit 6b0e170
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 13:07:06 2012 -0500

    Handle older installer environments and only allow binary gems when the
    environment specifically asks for it

commit b98eb78
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 04:05:13 2012 -0500

    Bump version to -testing

commit 6ac508c
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 02:25:09 2012 -0500

    Remove msf3 subdir

commit a27dac5
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 02:24:39 2012 -0500

    Remove the old busted external

commit 5fb5a0f
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 02:03:10 2012 -0500

    Add the gemcache loader

commit 09e2d89
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Apr 14 02:02:23 2012 -0500

    Purge gemfile/bundler configure in exchange for new gemcache setup

commit 3cc0264
Author: Tod Beardsley <todb@metasploit.com>
Date:   Thu Apr 12 14:11:45 2012 -0500

    Mode change on modicon_ladder.apx

commit c18b3d5
Author: HD Moore <hd_moore@rapid7.com>
Date:   Thu Apr 12 01:38:56 2012 -0500

    The go faster button

commit ca2a67d
Merge: 674ee09 b8129f9
Author: Tod Beardsley <todb@metasploit.com>
Date:   Mon Apr 9 15:50:33 2012 -0500

    Merge branch 'master-clone' into rails3-clone

    Picking up Packetfu upstream changes, all pretty minor

commit 674ee09
Merge: e9513e5 a26e844
Author: Tod Beardsley <todb@metasploit.com>
Date:   Mon Apr 9 13:57:26 2012 -0500

    Merge branch 'master-clone' into rails3-clone

    Conflicts:
    	lib/msf/core/handler/reverse_http.rb
    	lib/msf/core/handler/reverse_https.rb
    	modules/auxiliary/scanner/discovery/udp_probe.rb
    	modules/auxiliary/scanner/discovery/udp_sweep.rb

    Resolved conflicts with the reverse_http handlers and the udp probe /
    scanners byt favoring the more recent changes (which happened to be the
    intent anyway). The reverse_http and reverse_https changes were mine so
    I know what the intent was, and @dmaloney-r7 changed udp_probe and
    udp_sweep to use pcAnywhere_stat instead of merely pcAnywhere, so the
    intent is clear there as well.

commit e9513e5
Author: David Maloney <dmaloney@melodie.gateway.2wire.net>
Date:   Fri Apr 6 18:21:46 2012 -0500

    Some fixes to how services get reported to prevent issues with the web interface

commit adeb44e
Author: David Maloney <David_Maloney@rapid7.com>
Date:   Mon Apr 2 15:39:46 2012 -0500

    Some corrections to pcAnywhere discovery modules to distinguish between the two services

commit b139001
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Mar 31 12:03:21 2012 -0500

    Enable additional migration-path parameters, use a temporary directory to bring the database online

commit 526b4c5
Author: David Maloney <David_Maloney@rapid7.com>
Date:   Wed Mar 28 23:24:56 2012 -0500

    A bunch of Mdsm fixes for .kind_of? calls, to make sure we ponit to the right place

commit 2cf3143
Author: HD Moore <hd_moore@rapid7.com>
Date:   Mon Mar 26 16:22:09 2012 -0500

    Check for ruby 2.0 as well as 1.9 for encoding override

commit 4d0f51b
Author: HD Moore <hd_moore@rapid7.com>
Date:   Mon Mar 26 15:36:04 2012 -0500

    Remove debug statement

commit f5d2335
Author: HD Moore <hd_moore@rapid7.com>
Date:   Mon Mar 26 15:01:55 2012 -0500

    Be explicit about the Mdm namespace

commit bc8be22
Author: hdm <hdm@hypo.(none)>
Date:   Mon Mar 26 11:49:51 2012 -0500

    Precalculate some uri strings in case the 1000-round generation fails

commit 4254f41
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Sat Mar 24 14:03:44 2012 -0500

    Removed some non-namespaced calls to Host

commit c8190e1
Author: HD Moore <hd_moore@rapid7.com>
Date:   Tue Mar 20 00:37:00 2012 -0500

    Purge the rvmrc, this is causing major headaches

commit 76df185
Author: HD Moore <hd_moore@rapid7.com>
Date:   Tue Mar 20 00:31:52 2012 -0500

    Switch .rvmrc to the shipping 1.9.3 version

commit 7124971
Author: David Maloney <David_Maloney@rapid7.com>
Date:   Mon Mar 12 16:56:40 2012 -0500

    Adds mixin for looking up Mime Types by extension

commit b7ca835
Merge: a0b0c75 6b9a219
Author: Matt Buck <techpeace@gmail.com>
Date:   Tue Mar 6 19:38:53 2012 -0600

    Merge from develop.

commit a0b0c75
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Mar 6 11:08:59 2012 -0600

    Somehow migration file is new?

commit 84d2b3c
Author: David Maloney <David_Maloney@rapid7.com>
Date:   Wed Feb 29 16:38:55 2012 -0600

    Added ability to specify headers to redirects in http server

commit e50d27c
Author: HD Moore <hd_moore@rapid7.com>
Date:   Sat Feb 4 04:44:50 2012 -0600

    Tweak the event dispatcher to enable customer events without a category
    and trigger http request events from the main exploit mixin.
    Experimental

commit 0e4fd20
Author: Matt Buck <Matthew_Buck@rapid7.com>
Date:   Thu Feb 2 22:09:05 2012 -0600

    Change Msm -> Mdm in migrations. This is what was preventing migrations from finishing on first boot.

commit c94a296
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Wed Feb 1 12:48:48 2012 -0600

    Changed Gemfile to use new gem name

commit 245c206
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Wed Feb 1 12:47:42 2012 -0600

    Did find/replace for final namespace of Mdm

commit 6ed9bf8
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Jan 24 10:47:44 2012 -0600

    Fix a bunch of namespace issues

commit 2fe08d9
Author: Matt Buck <Matthew_Buck@rapid7.com>
Date:   Fri Jan 20 14:37:37 2012 -0600

    Update Msm contstants in migrations for initial DB builds.

commit 4cc6b8f
Author: Matt Buck <Matthew_Buck@rapid7.com>
Date:   Fri Jan 20 14:37:25 2012 -0600

    Update Gemfile.lock.

commit 1cc655b
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Thu Jan 19 11:48:29 2012 -0600

    Errant Workspaces needed namespace

commit 607a782
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Jan 17 15:44:02 2012 -0600

    Refactored all models to use the new namespace

    * Every model using DBManager::* namespace is now Msm namespace
    * Almost all of this in msf/base/core
    * Some in modules

commit a690cd9
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Jan 17 13:41:44 2012 -0600

    Move bundler setup

commit dae115c
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Mon Jan 9 15:51:07 2012 -0600

    Moved ActiveSupport dep to gem

commit d32f8ed
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Mon Jan 9 14:40:05 2012 -0600

    Removed model require file

commit d0c74cf
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Jan 3 16:06:10 2012 -0600

    Update some more finds

commit 4eb79ea
Author: Trevor Rosen <Trevor_Rosen@rapid7.com>
Date:   Tue Jan 3 14:21:15 2012 -0600

    Yet another dumb commit

commit a75febc
Author: Trevor Rosen <trevor@catapult-creative.com>
Date:   Thu Dec 29 19:20:51 2011 -0600

    Fixing deletion

commit dc139ff
Author: Trevor Rosen <trevor@catapult-creative.com>
Date:   Wed Dec 7 17:06:45 2011 -0600

    Fixed erroneous commit

commit 531c1e6
Author: Trevor Rosen <trevor@catapult-creative.com>
Date:   Mon Nov 21 16:11:35 2011 -0600

    Remove AR patch stuff; attempting to debug non-connection between MSF and Pro

commit 4586112
Author: Trevor Rosen <trevor@catapult-creative.com>
Date:   Fri Nov 18 16:17:27 2011 -0600

    Drop ActiveRecord/ActiveSupport in preparation for upgrade
  • Loading branch information...
commit 4bcbdc54c956bdf8800d5a1c1c84d9f5f53f8c40 1 parent 4be0361
Tod Beardsley todb authored
Showing with 426 additions and 32,851 deletions.
  1. +0 −3  .gitmodules
  2. +12 −0 Gemfile
  3. +388 −0 data/mime.yml
  4. +5 −5 data/sql/migrate/20100819123300_migrate_cred_data.rb
  5. +1 −1  data/sql/migrate/20100916151530_require_admin_flag.rb
  6. +8 −8 data/sql/migrate/20111203000000_inet_columns.rb
  7. +12 −0 documentation/Gemfile
  8. +0 −84 lib/active_record.rb
  9. +0 −261 lib/active_record/aggregations.rb
  10. +0 −389 lib/active_record/association_preload.rb
  11. +0 −2,241 lib/active_record/associations.rb
  12. +0 −475 lib/active_record/associations/association_collection.rb
  13. +0 −278 lib/active_record/associations/association_proxy.rb
  14. +0 −76 lib/active_record/associations/belongs_to_association.rb
  15. +0 −53 lib/active_record/associations/belongs_to_polymorphic_association.rb
  16. +0 −143 lib/active_record/associations/has_and_belongs_to_many_association.rb
  17. +0 −122 lib/active_record/associations/has_many_association.rb
  18. +0 −266 lib/active_record/associations/has_many_through_association.rb
  19. +0 −133 lib/active_record/associations/has_one_association.rb
  20. +0 −37 lib/active_record/associations/has_one_through_association.rb
  21. +0 −388 lib/active_record/attribute_methods.rb
  22. +0 −364 lib/active_record/autosave_association.rb
  23. +0 −3,165 lib/active_record/base.rb
  24. +0 −81 lib/active_record/batches.rb
  25. +0 −311 lib/active_record/calculations.rb
  26. +0 −360 lib/active_record/callbacks.rb
  27. +0 −371 lib/active_record/connection_adapters/abstract/connection_pool.rb
  28. +0 −139 lib/active_record/connection_adapters/abstract/connection_specification.rb
  29. +0 −289 lib/active_record/connection_adapters/abstract/database_statements.rb
  30. +0 −94 lib/active_record/connection_adapters/abstract/query_cache.rb
  31. +0 −69 lib/active_record/connection_adapters/abstract/quoting.rb
  32. +0 −722 lib/active_record/connection_adapters/abstract/schema_definitions.rb
  33. +0 −434 lib/active_record/connection_adapters/abstract/schema_statements.rb
  34. +0 −241 lib/active_record/connection_adapters/abstract_adapter.rb
  35. +0 −630 lib/active_record/connection_adapters/mysql_adapter.rb
  36. +0 −1,113 lib/active_record/connection_adapters/postgresql_adapter.rb
  37. +0 −34 lib/active_record/connection_adapters/sqlite3_adapter.rb
  38. +0 −453 lib/active_record/connection_adapters/sqlite_adapter.rb
  39. +0 −183 lib/active_record/dirty.rb
  40. +0 −41 lib/active_record/dynamic_finder_match.rb
  41. +0 −25 lib/active_record/dynamic_scope_match.rb
  42. +0 −996 lib/active_record/fixtures.rb
  43. +0 −26 lib/active_record/i18n_interpolation_deprecation.rb
  44. +0 −58 lib/active_record/locale/en.yml
  45. +0 −148 lib/active_record/locking/optimistic.rb
  46. +0 −55 lib/active_record/locking/pessimistic.rb
  47. +0 −566 lib/active_record/migration.rb
  48. +0 −192 lib/active_record/named_scope.rb
  49. +0 −392 lib/active_record/nested_attributes.rb
  50. +0 −197 lib/active_record/observer.rb
  51. +0 −33 lib/active_record/query_cache.rb
  52. +0 −320 lib/active_record/reflection.rb
  53. +0 −51 lib/active_record/schema.rb
  54. +0 −182 lib/active_record/schema_dumper.rb
  55. +0 −101 lib/active_record/serialization.rb
  56. +0 −91 lib/active_record/serializers/json_serializer.rb
  57. +0 −376 lib/active_record/serializers/xml_serializer.rb
  58. +0 −326 lib/active_record/session_store.rb
  59. +0 −66 lib/active_record/test_case.rb
  60. +0 −71 lib/active_record/timestamp.rb
  61. +0 −235 lib/active_record/transactions.rb
  62. +0 −1,134 lib/active_record/validations.rb
  63. +0 −9 lib/active_record/version.rb
  64. +0 −59 lib/active_support.rb
  65. +0 −8 lib/active_support/all.rb
  66. +0 −72 lib/active_support/backtrace_cleaner.rb
  67. +0 −33 lib/active_support/base64.rb
  68. +0 −24 lib/active_support/basic_object.rb
  69. +0 −127 lib/active_support/buffered_logger.rb
  70. +0 −248 lib/active_support/cache.rb
  71. +0 −20 lib/active_support/cache/compressed_mem_cache_store.rb
  72. +0 −14 lib/active_support/cache/drb_store.rb
  73. +0 −72 lib/active_support/cache/file_store.rb
  74. +0 −143 lib/active_support/cache/mem_cache_store.rb
  75. +0 −52 lib/active_support/cache/memory_store.rb
  76. +0 −104 lib/active_support/cache/strategy/local_cache.rb
  77. +0 −47 lib/active_support/cache/synchronized_memory_store.rb
  78. +0 −279 lib/active_support/callbacks.rb
  79. +0 −8 lib/active_support/core_ext.rb
  80. +0 −15 lib/active_support/core_ext/array.rb
  81. +0 −53 lib/active_support/core_ext/array/access.rb
  82. +0 −197 lib/active_support/core_ext/array/conversions.rb
  83. +0 −20 lib/active_support/core_ext/array/extract_options.rb
  84. +0 −106 lib/active_support/core_ext/array/grouping.rb
  85. +0 −12 lib/active_support/core_ext/array/random_access.rb
  86. +0 −24 lib/active_support/core_ext/array/wrapper.rb
  87. +0 −4 lib/active_support/core_ext/base64.rb
  88. +0 −16 lib/active_support/core_ext/base64/encoding.rb
  89. +0 −19 lib/active_support/core_ext/benchmark.rb
  90. +0 −6 lib/active_support/core_ext/bigdecimal.rb
  91. +0 −37 lib/active_support/core_ext/bigdecimal/conversions.rb
  92. +0 −2  lib/active_support/core_ext/blank.rb
  93. +0 −5 lib/active_support/core_ext/cgi.rb
  94. +0 −23 lib/active_support/core_ext/cgi/escape_skipping_slashes.rb
  95. +0 −4 lib/active_support/core_ext/class.rb
  96. +0 −54 lib/active_support/core_ext/class/attribute_accessors.rb
  97. +0 −47 lib/active_support/core_ext/class/delegating_attributes.rb
  98. +0 −140 lib/active_support/core_ext/class/inheritable_attributes.rb
  99. +0 −50 lib/active_support/core_ext/class/removal.rb
  100. +0 −10 lib/active_support/core_ext/date.rb
  101. +0 −42 lib/active_support/core_ext/date/behavior.rb
  102. +0 −231 lib/active_support/core_ext/date/calculations.rb
  103. +0 −107 lib/active_support/core_ext/date/conversions.rb
  104. +0 −12 lib/active_support/core_ext/date_time.rb
  105. +0 −126 lib/active_support/core_ext/date_time/calculations.rb
  106. +0 −96 lib/active_support/core_ext/date_time/conversions.rb
  107. +0 −43 lib/active_support/core_ext/duplicable.rb
  108. +0 −114 lib/active_support/core_ext/enumerable.rb
  109. +0 −45 lib/active_support/core_ext/exception.rb
  110. +0 −5 lib/active_support/core_ext/file.rb
  111. +0 −46 lib/active_support/core_ext/file/atomic.rb
  112. +0 −7 lib/active_support/core_ext/float.rb
  113. +0 −24 lib/active_support/core_ext/float/rounding.rb
  114. +0 −27 lib/active_support/core_ext/float/time.rb
  115. +0 −14 lib/active_support/core_ext/hash.rb
  116. +0 −247 lib/active_support/core_ext/hash/conversions.rb
  117. +0 −23 lib/active_support/core_ext/hash/deep_merge.rb
  118. +0 −19 lib/active_support/core_ext/hash/diff.rb
  119. +0 −25 lib/active_support/core_ext/hash/except.rb
  120. +0 −143 lib/active_support/core_ext/hash/indifferent_access.rb
  121. +0 −52 lib/active_support/core_ext/hash/keys.rb
  122. +0 −35 lib/active_support/core_ext/hash/reverse_merge.rb
  123. +0 −40 lib/active_support/core_ext/hash/slice.rb
  124. +0 −9 lib/active_support/core_ext/integer.rb
  125. +0 −29 lib/active_support/core_ext/integer/even_odd.rb
  126. +0 −20 lib/active_support/core_ext/integer/inflections.rb
  127. +0 −45 lib/active_support/core_ext/integer/time.rb
  128. +0 −5 lib/active_support/core_ext/kernel.rb
  129. +0 −11 lib/active_support/core_ext/kernel/agnostics.rb
  130. +0 −7 lib/active_support/core_ext/kernel/daemonizing.rb
  131. +0 −16 lib/active_support/core_ext/kernel/debugger.rb
  132. +0 −59 lib/active_support/core_ext/kernel/reporting.rb
  133. +0 −24 lib/active_support/core_ext/kernel/requires.rb
  134. +0 −38 lib/active_support/core_ext/load_error.rb
  135. +0 −145 lib/active_support/core_ext/logger.rb
  136. +0 −23 lib/active_support/core_ext/module.rb
  137. +0 −74 lib/active_support/core_ext/module/aliasing.rb
  138. +0 −31 lib/active_support/core_ext/module/attr_accessor_with_default.rb
  139. +0 −32 lib/active_support/core_ext/module/attr_internal.rb
  140. +0 −60 lib/active_support/core_ext/module/attribute_accessors.rb
  141. +0 −135 lib/active_support/core_ext/module/delegation.rb
  142. +0 −30 lib/active_support/core_ext/module/inclusion.rb
  143. +0 −90 lib/active_support/core_ext/module/introspection.rb
  144. +0 −23 lib/active_support/core_ext/module/loading.rb
  145. +0 −25 lib/active_support/core_ext/module/model_naming.rb
  146. +0 −39 lib/active_support/core_ext/module/synchronization.rb
  147. +0 −19 lib/active_support/core_ext/name_error.rb
  148. +0 −9 lib/active_support/core_ext/numeric.rb
  149. +0 −50 lib/active_support/core_ext/numeric/bytes.rb
  150. +0 −19 lib/active_support/core_ext/numeric/conversions.rb
  151. +0 −81 lib/active_support/core_ext/numeric/time.rb
  152. +0 −6 lib/active_support/core_ext/object.rb
  153. +0 −58 lib/active_support/core_ext/object/blank.rb
  154. +0 −15 lib/active_support/core_ext/object/conversions.rb
  155. +0 −80 lib/active_support/core_ext/object/extending.rb
  156. +0 −74 lib/active_support/core_ext/object/instance_variables.rb
  157. +0 −13 lib/active_support/core_ext/object/metaclass.rb
  158. +0 −90 lib/active_support/core_ext/object/misc.rb
  159. +0 −7 lib/active_support/core_ext/pathname.rb
  160. +0 −14 lib/active_support/core_ext/pathname/clean_within.rb
  161. +0 −12 lib/active_support/core_ext/proc.rb
  162. +0 −25 lib/active_support/core_ext/process/daemon.rb
  163. +0 −11 lib/active_support/core_ext/range.rb
  164. +0 −32 lib/active_support/core_ext/range/blockless_step.rb
  165. +0 −27 lib/active_support/core_ext/range/conversions.rb
  166. +0 −30 lib/active_support/core_ext/range/include_range.rb
  167. +0 −15 lib/active_support/core_ext/range/overlaps.rb
  168. +0 −41 lib/active_support/core_ext/rexml.rb
  169. +0 −25 lib/active_support/core_ext/string.rb
  170. +0 −106 lib/active_support/core_ext/string/access.rb
  171. +0 −13 lib/active_support/core_ext/string/behavior.rb
  172. +0 −5 lib/active_support/core_ext/string/bytesize.rb
  173. +0 −28 lib/active_support/core_ext/string/conversions.rb
  174. +0 −26 lib/active_support/core_ext/string/filters.rb
  175. +0 −167 lib/active_support/core_ext/string/inflections.rb
  176. +0 −23 lib/active_support/core_ext/string/iterators.rb
  177. +0 −81 lib/active_support/core_ext/string/multibyte.rb
  178. +0 −48 lib/active_support/core_ext/string/output_safety.rb
  179. +0 −35 lib/active_support/core_ext/string/starts_ends_with.rb
  180. +0 −11 lib/active_support/core_ext/string/xchar.rb
  181. +0 −14 lib/active_support/core_ext/symbol.rb
  182. +0 −42 lib/active_support/core_ext/time.rb
  183. +0 −13 lib/active_support/core_ext/time/behavior.rb
  184. +0 −304 lib/active_support/core_ext/time/calculations.rb
  185. +0 −90 lib/active_support/core_ext/time/conversions.rb
  186. +0 −86 lib/active_support/core_ext/time/zones.rb
  187. +0 −36 lib/active_support/core_ext/try.rb
  188. +0 −16 lib/active_support/core_ext/uri.rb
  189. +0 −614 lib/active_support/dependencies.rb
  190. +0 −196 lib/active_support/deprecation.rb
  191. +0 −100 lib/active_support/duration.rb
  192. +0 −25 lib/active_support/gzip.rb
  193. +0 −56 lib/active_support/inflections.rb
  194. +0 −406 lib/active_support/inflector.rb
  195. +0 −37 lib/active_support/json/backends/jsongem.rb
  196. +0 −84 lib/active_support/json/backends/yaml.rb
  197. +0 −35 lib/active_support/json/decoding.rb
  198. +0 −22 lib/active_support/json/encoders/date.rb
  199. +0 −22 lib/active_support/json/encoders/date_time.rb
  200. +0 −17 lib/active_support/json/encoders/enumerable.rb
  201. +0 −7 lib/active_support/json/encoders/false_class.rb
  202. +0 −56 lib/active_support/json/encoders/hash.rb
  203. +0 −7 lib/active_support/json/encoders/nil_class.rb
  204. +0 −21 lib/active_support/json/encoders/numeric.rb
  205. +0 −10 lib/active_support/json/encoders/object.rb
  206. +0 −9 lib/active_support/json/encoders/regexp.rb
  207. +0 −9 lib/active_support/json/encoders/string.rb
  208. +0 −5 lib/active_support/json/encoders/symbol.rb
  209. +0 −22 lib/active_support/json/encoders/time.rb
  210. +0 −7 lib/active_support/json/encoders/true_class.rb
  211. +0 −102 lib/active_support/json/encoding.rb
  212. +0 −10 lib/active_support/json/variable.rb
  213. +0 −33 lib/active_support/locale/en.yml
  214. +0 −100 lib/active_support/memoizable.rb
  215. +0 −70 lib/active_support/message_encryptor.rb
  216. +0 −79 lib/active_support/message_verifier.rb
  217. +0 −57 lib/active_support/multibyte.rb
  218. +0 −707 lib/active_support/multibyte/chars.rb
  219. +0 −71 lib/active_support/multibyte/unicode_database.rb
  220. +0 −61 lib/active_support/multibyte/utils.rb
  221. +0 −23 lib/active_support/option_merger.rb
  222. +0 −141 lib/active_support/ordered_hash.rb
  223. +0 −19 lib/active_support/ordered_options.rb
  224. +0 −108 lib/active_support/rescuable.rb
  225. +0 −199 lib/active_support/secure_random.rb
  226. +0 −40 lib/active_support/test_case.rb
  227. +0 −65 lib/active_support/testing/assertions.rb
  228. +0 −21 lib/active_support/testing/declarative.rb
  229. +0 −9 lib/active_support/testing/default.rb
  230. +0 −57 lib/active_support/testing/deprecation.rb
  231. +0 −452 lib/active_support/testing/performance.rb
  232. +0 −91 lib/active_support/testing/setup_and_teardown.rb
  233. +0 −335 lib/active_support/time_with_zone.rb
  234. +0 −404 lib/active_support/values/time_zone.rb
  235. BIN  lib/active_support/values/unicode_tables.dat
  236. +0 −28 lib/active_support/vendor.rb
  237. +0 −113 lib/active_support/vendor/builder-2.1.2/blankslate.rb
  238. +0 −20 lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb
  239. +0 −250 lib/active_support/vendor/builder-2.1.2/builder/css.rb
  240. +0 −115 lib/active_support/vendor/builder-2.1.2/builder/xchar.rb
  241. +0 −139 lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb
  242. +0 −63 lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
  243. +0 −328 lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb
  244. +0 −20 lib/active_support/vendor/i18n-0.1.3/README.textile
  245. +0 −5 lib/active_support/vendor/i18n-0.1.3/Rakefile
  246. +0 −27 lib/active_support/vendor/i18n-0.1.3/i18n.gemspec
  247. +0 −199 lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb
  248. +0 −214 lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb
  249. +0 −53 lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb
  250. +0 −5 lib/active_support/vendor/i18n-0.1.3/test/all.rb
Sorry, we could not display the entire diff because too many files (8,021) changed.
3  .gitmodules
View
@@ -1,3 +0,0 @@
-[submodule "lib/msf3"]
- path = lib/msf3
- url = git@framework.github.com:rapid7/metasploit-framework.git
12 Gemfile
View
@@ -0,0 +1,12 @@
+source 'http://rubygems.org'
+gem 'rails', '3.2.2'
+gem 'authlogic'
+gem 'prototype_legacy_helper', '0.0.0', :git => 'git://github.com/jvennix-r7/prototype_legacy_helper.git'
+gem 'state_machine', '1.1.2'
+gem 'liquid', '2.3.0'
+gem 'ice_cube'
+gem 'acts_as_list'
+gem 'mime-types', '1.18', :git => "git://github.com/rapid7/mime-types.git"
+gem 'metasploit_data_models', '0.0.2', :git => "git://github.com/rapid7/metasploit_data_models.git"
+gem 'robots', '0.10.1'
+
388 data/mime.yml
View
@@ -0,0 +1,388 @@
+# EXTENSIONS => CONTENT TYPE
+csh: application/x-csh
+x_t: model/vnd.parasolid.transmit.text
+kpt: application/vnd.kde.kpresenter
+vst: application/vnd.visio
+ksp: application/vnd.kde.kspread
+fsc: application/vnd.fsc.weblaunch
+vcs: text/x-vcalendar
+hvs: application/vnd.yamaha.hv-script
+seml: application/vnd.sealed.eml
+lzh: application/octet-stream
+movie: video/x-sgi-movie
+wav: audio/x-wav
+tbz2: application/x-gtar
+plt: application/vnd.hp-HPGL
+3gpp: video/3gpp
+eol: audio/vnd.digital-winds
+vsw: application/vnd.visio
+rtf: text/rtf
+rgb: image/x-rgb
+midi: audio/x-midi
+sit: application/x-stuffit
+mov: video/quicktime
+kfo: application/vnd.kde.kformula
+rdf: application/rdf+xml
+wpd: application/vnd.wordperfect
+hbc: application/vnd.hbci
+ogg: application/ogg
+dwf: x-drawing/dwf
+pbm: image/x-portable-bitmap
+cpp: text/plain
+smp3: audio/vnd.sealedmedia.softseal.mpeg
+html: text/html
+igs: model/iges
+dwg: image/vnd.dwg
+see: application/vnd.seemail
+ram: audio/x-pn-realaudio
+jad: text/vnd.sun.j2me.app-descriptor
+iges: model/iges
+pot: application/powerpoint
+exe: application/octet-stream
+siv: application/sieve
+wml: text/vnd.wap.wml
+hlp: text/plain
+pkd: application/vnd.hbci
+ice: x-conference/x-cooltalk
+ustar: application/x-ustar
+vis: application/vnd.visionary
+pkipath: application/pkix-pkipath
+ecelp4800: audio/vnd.nuera.ecelp4800
+tgz: application/x-gtar
+roff: text/troff
+ltx: application/x-latex
+nim: video/vnd.nokia.interleaved-multimedia
+qcp: audio/QCELP
+ai: application/postscript
+sppt: application/vnd.sealed.ppt
+igx: application/vnd.micrografx.igx
+tcl: application/x-tcl
+viv: video/vnd.vivo
+css: text/css
+wpl: application/vnd.ms-wpl
+ami: application/vnd.amiga.ami
+l16: audio/L16
+vivo: video/vnd.vivo
+dat: text/plain
+vrml: x-world/x-vrml
+pqa: application/vnd.palm
+request: application/vnd.nervana
+oprc: application/vnd.palm
+vbk: audio/vnd.nortel.vbk
+pki: application/pkixcmp
+ras: image/x-cmu-raster
+asc: text/plain
+kom: application/vnd.hbci
+jpeg: image/jpeg
+sem: application/vnd.sealed.eml
+chrt: application/vnd.kde.kchart
+tif: image/tiff
+cil: application/vnd.ms-artgalry
+xwd: image/x-xwindowdump
+dgn: image/x-vnd.dgn
+mxu: video/vnd.mpegurl
+csv: text/comma-separated-values
+kon: application/vnd.kde.kontour
+png: image/png
+bkm: application/vnd.nervana
+sxl: application/vnd.sealed.xls
+xfdf: application/vnd.adobe.xfdf
+snd: audio/basic
+dl: video/dl
+sxls: application/vnd.sealed.xls
+karbon: application/vnd.kde.karbon
+ico: image/vnd.microsoft.icon
+sus: application/vnd.sus-calendar
+pdb: x-chemical/x-pdb
+wif: application/watcherinfo+xml
+ser: application/x-java-serialized-object
+xmt_txt: model/vnd.parasolid.transmit.text
+upa: application/vnd.hbci
+pnm: image/x-portable-anymap
+jar: application/x-java-archive
+qt: video/quicktime
+tsv: text/tab-separated-values
+rtx: text/richtext
+mdi: image/vnd.ms-modi
+rcprofile: application/vnd.ipunplugged.rcprofile
+gl: video/gl
+me: application/x-troff-me
+man: application/x-troff-man
+tr: text/troff
+amr: audio/AMR
+wp5: application/wordperfect5.1
+pdf: application/pdf
+pgb: image/vnd.globalgraphics.pgb
+au: audio/basic
+avi: video/x-msvideo
+qxb: application/vnd.Quark.QuarkXPress
+wp: application/wordperfect5.1
+wmlsc: application/vnd.wap.wmlscriptc
+wbxml: application/vnd.wap.wbxml
+s1a: application/vnd.sealedmedia.softseal.pdf
+saf: application/vnd.yamaha.smaf-audio
+gtar: application/x-gtar
+Z: application/x-compressed
+crl: application/pkix-crl
+pti: application/vnd.pvi.ptid1
+rdz: application/vnd.data-vision.rdz
+aif: audio/x-aiff
+flo: application/vnd.micrografx.flo
+qxd: application/vnd.Quark.QuarkXPress
+rpm: audio/x-pn-realaudio-plugin
+djv: image/vnd.djvu
+jpe: image/jpeg
+kne: application/vnd.Kinar
+lvp: audio/vnd.lucent.voice
+stml: application/vnd.sealedmedia.softseal.html
+p7c: application/pkcs7-mime
+dms: application/octet-stream
+s1e: application/vnd.sealed.xls
+sdf: application/vnd.Kinar
+sc: application/vnd.ibm.secure-container
+jnlp: application/x-java-jnlp-file
+dvi: application/x-dvi
+smov: video/vnd.sealedmedia.softseal.mov
+jisp: application/vnd.jisp
+aifc: audio/x-aiff
+latex: application/x-latex
+cc: text/plain
+s1g: image/vnd.sealedmedia.softseal.gif
+wv: application/vnd.wv.csp+wbxml
+mseq: application/vnd.mseq
+jpg: image/jpeg
+mmf: application/vnd.smaf
+xmt_bin: model/vnd.parasolid.transmit.binary
+s1h: application/vnd.sealedmedia.softseal.html
+mpc: application/vnd.mophun.certificate
+hdf: application/x-hdf
+stk: application/hyperstudio
+txd: application/vnd.genomatix.tuxedo
+ent: application/vnd.nervana
+xml: text/xml
+aiff: audio/x-aiff
+sh: application/x-sh
+mpe: video/mpeg
+s1j: image/vnd.sealedmedia.softseal.jpg
+psid: audio/prs.sid
+mpga: audio/mpeg
+pgm: image/x-portable-graymap
+si: text/vnd.wap.si
+stm: application/vnd.sealedmedia.softseal.html
+lbd: application/vnd.llamagraphics.life-balance.desktop
+flw: application/vnd.kde.kivio
+mpg: video/mpeg
+c: text/plain
+sgi: image/vnd.sealedmedia.softseal.gif
+zip: application/zip
+ecelp7470: audio/vnd.nuera.ecelp7470
+lbe: application/vnd.llamagraphics.life-balance.exchange+xml
+qxl: application/vnd.Quark.QuarkXPress
+p10: application/pkcs10
+bpd: application/vnd.hbci
+ief: image/ief
+gz: application/x-gzip
+doc: application/word
+efif: application/vnd.picsel
+jpm: image/jpm
+hpgl: application/vnd.hp-HPGL
+s1m: audio/vnd.sealedmedia.softseal.mpeg
+xhtml: application/xhtml+xml
+xpm: image/x-xpixmap
+ms: application/x-troff-ms
+bcpio: application/x-bcpio
+sl: text/vnd.wap.sl
+wrl: x-world/x-vrml
+s1n: image/vnd.sealed.png
+irm: application/vnd.ibm.rights-management
+pgp: application/octet-stream
+entity: application/vnd.nervana
+mcd: application/vnd.mcd
+ecelp9600: audio/vnd.nuera.ecelp9600
+kwd: application/vnd.kde.kword
+gif: image/gif
+sdo: application/vnd.sealed.doc
+cer: application/pkix-cert
+m4u: video/vnd.mpegurl
+rst: text/prs.fallenstein.rst
+htm: text/html
+mxmf: audio/vnd.nokia.mobile-xmf
+psb: application/vnd.3gpp.pic-bw-small
+knp: application/vnd.Kinar
+cab: application/vnd.ms-cab-compressed
+mj2: video/MJ2
+sgm: text/sgml
+wbmp: image/vnd.wap.wbmp
+p7m: application/pkcs7-mime
+spng: image/vnd.sealed.png
+lha: application/octet-stream
+s1p: application/vnd.sealed.ppt
+texi: application/x-texinfo
+s1q: video/vnd.sealedmedia.softseal.mov
+troff: text/troff
+h: text/plain
+shtml: text/html
+msh: model/mesh
+irp: application/vnd.irepository.package+xml
+rct: application/prs.nprend
+smht: application/vnd.sealed.mht
+s11: video/vnd.sealed.mpeg1
+htke: application/vnd.kenameaapp
+ps: application/postscript
+mpm: application/vnd.blueice.multipass
+dfac: application/vnd.dreamfactory
+pvb: application/vnd.3gpp.pic-bw-var
+lrm: application/vnd.ms-lrm
+smh: application/vnd.sealed.mht
+mpn: application/vnd.mophun.application
+spd: application/vnd.sealedmedia.softseal.pdf
+tiff: image/tiff
+jp2: image/jp2
+rpss: application/vnd.nokia.radio-presets
+qxt: application/vnd.Quark.QuarkXPress
+wmlc: application/vnd.wap.wmlc
+rpst: application/vnd.nokia.radio-preset
+etx: text/x-setext
+bmp: image/bmp
+s14: video/vnd.sealed.mpeg4
+\"123\": application/vnd.lotus-1-2-3
+mpp: application/vnd.ms-project
+spf: application/vnd.yamaha.smaf-phrase
+kar: audio/x-midi
+mid: audio/x-midi
+3gp: video/3gpp
+3g2: video/3gpp2
+hqx: application/mac-binhex40
+p7s: application/pkcs7-signature
+ppm: image/x-portable-pixmap
+pspimage: image/x-paintshoppro
+cdf: application/netcdf
+texinfo: application/x-texinfo
+sjp: image/vnd.sealedmedia.softseal.jpg
+wbs: application/vnd.criticaltools.wbs+xml
+emm: application/vnd.ibm.electronic-media
+s1w: application/vnd.sealed.doc
+ra: audio/x-realaudio
+jpx: image/jpx
+evc: audio/EVRC
+mif: application/x-mif
+qwd: application/vnd.Quark.QuarkXPress
+mp2: video/mpeg
+spdf: application/vnd.sealedmedia.softseal.pdf
+tbz: application/x-gtar
+txt: text/plain
+x_b: model/vnd.parasolid.transmit.binary
+mp3: audio/mpeg
+class: application/x-java-vm
+smo: video/vnd.sealedmedia.softseal.mov
+mp4: video/vnd.objectvideo
+m4v: video/x-m4v
+htx: text/html
+hbci: application/vnd.hbci
+tex: application/x-tex
+vsc: application/vnd.vidsoft.vidconference
+wqd: application/vnd.wqd
+mfm: application/vnd.mfmp
+sgml: text/sgml
+smp: audio/vnd.sealedmedia.softseal.mpeg
+curl: application/vnd.curl
+cw: application/prs.cww
+djvu: image/vnd.djvu
+tga: image/targa
+vsd: application/vnd.visio
+t: text/troff
+wtb: application/vnd.webturbo
+spn: image/vnd.sealed.png
+plb: application/vnd.3gpp.pic-bw-large
+pps: application/powerpoint
+yaml: text/x-yaml
+psp: image/x-paintshoppro
+mjp2: video/MJ2
+sms: application/vnd.3gpp.sms
+hvd: application/vnd.yamaha.hv-dic
+acutc: application/vnd.acucorp
+ppt: application/powerpoint
+les: application/vnd.hhe.lesson-player
+vcf: text/x-vcard
+sjpg: image/vnd.sealedmedia.softseal.jpg
+kwt: application/vnd.kde.kword
+sic: application/vnd.wap.sic
+spp: application/vnd.sealed.ppt
+cmc: application/vnd.cosmocaller
+dot: application/word
+sv4cpio: application/x-sv4cpio
+cpio: application/x-cpio
+sswf: video/vnd.sealed.swf
+silo: model/mesh
+sid: audio/prs.sid
+yml: text/x-yaml
+smv: audio/SMV
+eps: application/postscript
+ptid: application/vnd.pvi.ptid1
+wks: application/vnd.lotus-1-2-3
+z: application/x-compressed
+hpp: text/plain
+htmlx: text/html
+ani: application/octet-stream
+sig: application/pgp-signature
+slc: application/vnd.wap.slc
+rm: audio/x-pn-realaudio
+smpg: video/vnd.sealed.mpeg4
+wmls: text/vnd.wap.wmlscript
+bin: application/x-mac
+mesh: model/mesh
+atc: application/vnd.acucorp
+pfr: application/font-tdpfr
+plj: audio/vnd.everad.plj
+rnd: application/prs.nprend
+xls: application/excel
+tar: application/x-tar
+mp3g: video/mpeg
+sgif: image/vnd.sealedmedia.softseal.gif
+oda: application/oda
+sdoc: application/vnd.sealed.doc
+kia: application/vnd.kidspiration
+prc: application/vnd.palm
+req: application/vnd.nervana
+xyz: x-chemical/x-xyz
+soc: application/sgml-open-catalog
+xlt: application/excel
+awb: audio/AMR-WB
+susp: application/vnd.sus-calendar
+xbm: image/x-xbm
+ccc: text/vnd.net2phone.commcenter.command
+hh: text/plain
+qwt: application/vnd.Quark.QuarkXPress
+shar: application/x-shar
+ssw: video/vnd.sealed.swf
+xul: application/vnd.mozilla.xul+xml
+kcm: application/vnd.nervana
+kpr: application/vnd.kde.kpresenter
+cdy: application/vnd.cinderella
+nc: application/netcdf
+src: application/x-wais-source
+sv4crc: application/x-sv4crc
+dtd: text/xml
+hvp: application/vnd.yamaha.hv-voice
+cww: application/prs.cww
+vss: application/vnd.visio
+rb: application/x-ruby
+log: text/plain
+swf: application/x-shockwave-flash
+flv: video/x-flv
+asf: video/x-ms-asf
+asx: video/x-ms-asf
+wma: audio/x-ms-wma
+wax: audio/x-ms-wax
+wmv: audio/x-ms-wmv
+wvx: video/x-ms-wvx
+wm: video/x-ms-wm
+wmx: video/x-ms-wmx
+wmz: application/x-ms-wmz
+wmd: application/x-ms-wmd
+m3u: audio/x-mpequrl
+rdp: application/rdp
+pcap: application/vnd.tcpdump.pcap
+torrent: application/x-bittorrent
+xlb: application/excel
+cue: application/x-cue
10 data/sql/migrate/20100819123300_migrate_cred_data.rb
View
@@ -4,7 +4,7 @@ def self.up
begin # Wrap the whole thing in a giant rescue.
skipped_notes = []
new_creds = []
- Msf::DBManager::Note.find(:all).each do |note|
+ Mdm::Note.find(:all).each do |note|
next unless note.ntype[/^auth\.(.*)/]
service_name = $1
if !service_name
@@ -46,7 +46,7 @@ def self.up
if candidate_services.size == 1
svc_id = candidate_services.first.id
elsif candidate_services.empty?
- Msf::DBManager::Service.new do |svc|
+ Mdm::Service.new do |svc|
svc.host_id = note.host.id
svc.port = default_port
svc.proto = 'tcp'
@@ -115,7 +115,7 @@ def self.up
say "Migrating #{new_creds.size} credentials."
new_creds.uniq.each do |note|
- Msf::DBManager::Cred.new do |cred|
+ Mdm::Cred.new do |cred|
cred.service_id = note[0]
cred.user = note[2]
cred.pass = note[3]
@@ -126,7 +126,7 @@ def self.up
say "Migrating #{skipped_notes.size} notes."
skipped_notes.uniq.each do |note|
- Msf::DBManager::Note.new do |new_note|
+ Mdm::Note.new do |new_note|
new_note.host_id = note.host_id
new_note.ntype = "migrated_auth"
new_note.data = note.data.merge(:migrated_auth_type => note.ntype)
@@ -135,7 +135,7 @@ def self.up
end
say "Deleting migrated auth notes."
- Msf::DBManager::Note.find(:all).each do |note|
+ Mdm::Note.find(:all).each do |note|
next unless note.ntype[/^auth\.(.*)/]
note.delete
end
2  data/sql/migrate/20100916151530_require_admin_flag.rb
View
@@ -3,7 +3,7 @@ class RequireAdminFlag < ActiveRecord::Migration
# Make the admin flag required.
def self.up
# update any existing records
- Msf::DBManager::User.update_all({:admin => true}, {:admin => nil})
+ Mdm::User.update_all({:admin => true}, {:admin => nil})
change_column :users, :admin, :boolean, :null => false, :default => true
end
16 data/sql/migrate/20111203000000_inet_columns.rb
View
@@ -1,13 +1,13 @@
class InetColumns < ActiveRecord::Migration
- def self.up
- change_column :hosts, :address, 'INET using address::INET'
- remove_column :hosts, :address6
- end
+ def self.up
+ change_column :hosts, :address, 'INET using address::INET'
+ remove_column :hosts, :address6
+ end
- def self.down
- change_column :hosts, :address, :text
- add_column :hosts, :address6, :text
- end
+ def self.down
+ change_column :hosts, :address, :text
+ add_column :hosts, :address6, :text
+ end
end
12 documentation/Gemfile
View
@@ -0,0 +1,12 @@
+source 'http://rubygems.org'
+gem 'rails', '3.2.2'
+gem 'authlogic'
+gem 'prototype_legacy_helper', '0.0.0', :git => 'git://github.com/jvennix-r7/prototype_legacy_helper.git'
+gem 'state_machine', '1.1.2'
+gem 'liquid', '2.3.0'
+gem 'ice_cube'
+gem 'acts_as_list'
+gem 'mime-types', '1.18', :git => "git://github.com/rapid7/mime-types.git"
+gem 'metasploit_data_models', '0.0.2', :git => "git://github.com/rapid7/metasploit_data_models.git"
+gem 'robots', '0.10.1'
+
84 lib/active_record.rb
View
@@ -1,84 +0,0 @@
-#--
-# Copyright (c) 2004-2009 David Heinemeier Hansson
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-
-begin
- require 'active_support'
-rescue LoadError
- activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
- if File.directory?(activesupport_path)
- $:.unshift activesupport_path
- require 'active_support'
- end
-end
-
-module ActiveRecord
- # TODO: Review explicit loads to see if they will automatically be handled by the initilizer.
- def self.load_all!
- [Base, DynamicFinderMatch, ConnectionAdapters::AbstractAdapter]
- end
-
- autoload :VERSION, 'active_record/version'
-
- autoload :ActiveRecordError, 'active_record/base'
- autoload :ConnectionNotEstablished, 'active_record/base'
-
- autoload :Aggregations, 'active_record/aggregations'
- autoload :AssociationPreload, 'active_record/association_preload'
- autoload :Associations, 'active_record/associations'
- autoload :AttributeMethods, 'active_record/attribute_methods'
- autoload :AutosaveAssociation, 'active_record/autosave_association'
- autoload :Base, 'active_record/base'
- autoload :Batches, 'active_record/batches'
- autoload :Calculations, 'active_record/calculations'
- autoload :Callbacks, 'active_record/callbacks'
- autoload :Dirty, 'active_record/dirty'
- autoload :DynamicFinderMatch, 'active_record/dynamic_finder_match'
- autoload :DynamicScopeMatch, 'active_record/dynamic_scope_match'
- autoload :Migration, 'active_record/migration'
- autoload :Migrator, 'active_record/migration'
- autoload :NamedScope, 'active_record/named_scope'
- autoload :NestedAttributes, 'active_record/nested_attributes'
- autoload :Observing, 'active_record/observer'
- autoload :QueryCache, 'active_record/query_cache'
- autoload :Reflection, 'active_record/reflection'
- autoload :Schema, 'active_record/schema'
- autoload :SchemaDumper, 'active_record/schema_dumper'
- autoload :Serialization, 'active_record/serialization'
- autoload :SessionStore, 'active_record/session_store'
- autoload :TestCase, 'active_record/test_case'
- autoload :Timestamp, 'active_record/timestamp'
- autoload :Transactions, 'active_record/transactions'
- autoload :Validations, 'active_record/validations'
-
- module Locking
- autoload :Optimistic, 'active_record/locking/optimistic'
- autoload :Pessimistic, 'active_record/locking/pessimistic'
- end
-
- module ConnectionAdapters
- autoload :AbstractAdapter, 'active_record/connection_adapters/abstract_adapter'
- end
-end
-
-require 'active_record/i18n_interpolation_deprecation'
-I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
261 lib/active_record/aggregations.rb
View
@@ -1,261 +0,0 @@
-module ActiveRecord
- module Aggregations # :nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- def clear_aggregation_cache #:nodoc:
- self.class.reflect_on_all_aggregations.to_a.each do |assoc|
- instance_variable_set "@#{assoc.name}", nil
- end unless self.new_record?
- end
-
- # Active Record implements aggregation through a macro-like class method called +composed_of+ for representing attributes
- # as value objects. It expresses relationships like "Account [is] composed of Money [among other things]" or "Person [is]
- # composed of [an] address". Each call to the macro adds a description of how the value objects are created from the
- # attributes of the entity object (when the entity is initialized either as a new object or from finding an existing object)
- # and how it can be turned back into attributes (when the entity is saved to the database). Example:
- #
- # class Customer < ActiveRecord::Base
- # composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
- # composed_of :address, :mapping => [ %w(address_street street), %w(address_city city) ]
- # end
- #
- # The customer class now has the following methods to manipulate the value objects:
- # * <tt>Customer#balance, Customer#balance=(money)</tt>
- # * <tt>Customer#address, Customer#address=(address)</tt>
- #
- # These methods will operate with value objects like the ones described below:
- #
- # class Money
- # include Comparable
- # attr_reader :amount, :currency
- # EXCHANGE_RATES = { "USD_TO_DKK" => 6 }
- #
- # def initialize(amount, currency = "USD")
- # @amount, @currency = amount, currency
- # end
- #
- # def exchange_to(other_currency)
- # exchanged_amount = (amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor
- # Money.new(exchanged_amount, other_currency)
- # end
- #
- # def ==(other_money)
- # amount == other_money.amount && currency == other_money.currency
- # end
- #
- # def <=>(other_money)
- # if currency == other_money.currency
- # amount <=> amount
- # else
- # amount <=> other_money.exchange_to(currency).amount
- # end
- # end
- # end
- #
- # class Address
- # attr_reader :street, :city
- # def initialize(street, city)
- # @street, @city = street, city
- # end
- #
- # def close_to?(other_address)
- # city == other_address.city
- # end
- #
- # def ==(other_address)
- # city == other_address.city && street == other_address.street
- # end
- # end
- #
- # Now it's possible to access attributes from the database through the value objects instead. If you choose to name the
- # composition the same as the attribute's name, it will be the only way to access that attribute. That's the case with our
- # +balance+ attribute. You interact with the value objects just like you would any other attribute, though:
- #
- # customer.balance = Money.new(20) # sets the Money value object and the attribute
- # customer.balance # => Money value object
- # customer.balance.exchange_to("DKK") # => Money.new(120, "DKK")
- # customer.balance > Money.new(10) # => true
- # customer.balance == Money.new(20) # => true
- # customer.balance < Money.new(5) # => false
- #
- # Value objects can also be composed of multiple attributes, such as the case of Address. The order of the mappings will
- # determine the order of the parameters. Example:
- #
- # customer.address_street = "Hyancintvej"
- # customer.address_city = "Copenhagen"
- # customer.address # => Address.new("Hyancintvej", "Copenhagen")
- # customer.address = Address.new("May Street", "Chicago")
- # customer.address_street # => "May Street"
- # customer.address_city # => "Chicago"
- #
- # == Writing value objects
- #
- # Value objects are immutable and interchangeable objects that represent a given value, such as a Money object representing
- # $5. Two Money objects both representing $5 should be equal (through methods such as <tt>==</tt> and <tt><=></tt> from Comparable if ranking
- # makes sense). This is unlike entity objects where equality is determined by identity. An entity class such as Customer can
- # easily have two different objects that both have an address on Hyancintvej. Entity identity is determined by object or
- # relational unique identifiers (such as primary keys). Normal ActiveRecord::Base classes are entity objects.
- #
- # It's also important to treat the value objects as immutable. Don't allow the Money object to have its amount changed after
- # creation. Create a new Money object with the new value instead. This is exemplified by the Money#exchange_to method that
- # returns a new value object instead of changing its own values. Active Record won't persist value objects that have been
- # changed through means other than the writer method.
- #
- # The immutable requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to
- # change it afterwards will result in a ActiveSupport::FrozenObjectError.
- #
- # Read more about value objects on http://c2.com/cgi/wiki?ValueObject and on the dangers of not keeping value objects
- # immutable on http://c2.com/cgi/wiki?ValueObjectsShouldBeImmutable
- #
- # == Custom constructors and converters
- #
- # By default value objects are initialized by calling the <tt>new</tt> constructor of the value class passing each of the
- # mapped attributes, in the order specified by the <tt>:mapping</tt> option, as arguments. If the value class doesn't support
- # this convention then +composed_of+ allows a custom constructor to be specified.
- #
- # When a new value is assigned to the value object the default assumption is that the new value is an instance of the value
- # class. Specifying a custom converter allows the new value to be automatically converted to an instance of value class if
- # necessary.
- #
- # For example, the NetworkResource model has +network_address+ and +cidr_range+ attributes that should be aggregated using the
- # NetAddr::CIDR value class (http://netaddr.rubyforge.org). The constructor for the value class is called +create+ and it
- # expects a CIDR address string as a parameter. New values can be assigned to the value object using either another
- # NetAddr::CIDR object, a string or an array. The <tt>:constructor</tt> and <tt>:converter</tt> options can be used to
- # meet these requirements:
- #
- # class NetworkResource < ActiveRecord::Base
- # composed_of :cidr,
- # :class_name => 'NetAddr::CIDR',
- # :mapping => [ %w(network_address network), %w(cidr_range bits) ],
- # :allow_nil => true,
- # :constructor => Proc.new { |network_address, cidr_range| NetAddr::CIDR.create("#{network_address}/#{cidr_range}") },
- # :converter => Proc.new { |value| NetAddr::CIDR.create(value.is_a?(Array) ? value.join('/') : value) }
- # end
- #
- # # This calls the :constructor
- # network_resource = NetworkResource.new(:network_address => '192.168.0.1', :cidr_range => 24)
- #
- # # These assignments will both use the :converter
- # network_resource.cidr = [ '192.168.2.1', 8 ]
- # network_resource.cidr = '192.168.0.1/24'
- #
- # # This assignment won't use the :converter as the value is already an instance of the value class
- # network_resource.cidr = NetAddr::CIDR.create('192.168.2.1/8')
- #
- # # Saving and then reloading will use the :constructor on reload
- # network_resource.save
- # network_resource.reload
- #
- # == Finding records by a value object
- #
- # Once a +composed_of+ relationship is specified for a model, records can be loaded from the database by specifying an instance
- # of the value object in the conditions hash. The following example finds all customers with +balance_amount+ equal to 20 and
- # +balance_currency+ equal to "USD":
- #
- # Customer.find(:all, :conditions => {:balance => Money.new(20, "USD")})
- #
- module ClassMethods
- # Adds reader and writer methods for manipulating a value object:
- # <tt>composed_of :address</tt> adds <tt>address</tt> and <tt>address=(new_address)</tt> methods.
- #
- # Options are:
- # * <tt>:class_name</tt> - Specifies the class name of the association. Use it only if that name can't be inferred
- # from the part id. So <tt>composed_of :address</tt> will by default be linked to the Address class, but
- # if the real class name is CompanyAddress, you'll have to specify it with this option.
- # * <tt>:mapping</tt> - Specifies the mapping of entity attributes to attributes of the value object. Each mapping
- # is represented as an array where the first item is the name of the entity attribute and the second item is the
- # name the attribute in the value object. The order in which mappings are defined determine the order in which
- # attributes are sent to the value class constructor.
- # * <tt>:allow_nil</tt> - Specifies that the value object will not be instantiated when all mapped
- # attributes are +nil+. Setting the value object to +nil+ has the effect of writing +nil+ to all mapped attributes.
- # This defaults to +false+.
- # * <tt>:constructor</tt> - A symbol specifying the name of the constructor method or a Proc that is called to
- # initialize the value object. The constructor is passed all of the mapped attributes, in the order that they
- # are defined in the <tt>:mapping option</tt>, as arguments and uses them to instantiate a <tt>:class_name</tt> object.
- # The default is <tt>:new</tt>.
- # * <tt>:converter</tt> - A symbol specifying the name of a class method of <tt>:class_name</tt> or a Proc that is
- # called when a new value is assigned to the value object. The converter is passed the single value that is used
- # in the assignment and is only called if the new value is not an instance of <tt>:class_name</tt>.
- #
- # Option examples:
- # composed_of :temperature, :mapping => %w(reading celsius)
- # composed_of :balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| balance.to_money }
- # composed_of :address, :mapping => [ %w(address_street street), %w(address_city city) ]
- # composed_of :gps_location
- # composed_of :gps_location, :allow_nil => true
- # composed_of :ip_address,
- # :class_name => 'IPAddr',
- # :mapping => %w(ip to_i),
- # :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
- # :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
- #
- def composed_of(part_id, options = {}, &block)
- options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
-
- name = part_id.id2name
- class_name = options[:class_name] || name.camelize
- mapping = options[:mapping] || [ name, name ]
- mapping = [ mapping ] unless mapping.first.is_a?(Array)
- allow_nil = options[:allow_nil] || false
- constructor = options[:constructor] || :new
- converter = options[:converter] || block
-
- ActiveSupport::Deprecation.warn('The conversion block has been deprecated, use the :converter option instead.', caller) if block_given?
-
- reader_method(name, class_name, mapping, allow_nil, constructor)
- writer_method(name, class_name, mapping, allow_nil, converter)
-
- create_reflection(:composed_of, part_id, options, self)
- end
-
- private
- def reader_method(name, class_name, mapping, allow_nil, constructor)
- module_eval do
- define_method(name) do |*args|
- force_reload = args.first || false
- if (instance_variable_get("@#{name}").nil? || force_reload) && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? })
- attrs = mapping.collect {|pair| read_attribute(pair.first)}
- object = case constructor
- when Symbol
- class_name.constantize.send(constructor, *attrs)
- when Proc, Method
- constructor.call(*attrs)
- else
- raise ArgumentError, 'Constructor must be a symbol denoting the constructor method to call or a Proc to be invoked.'
- end
- instance_variable_set("@#{name}", object)
- end
- instance_variable_get("@#{name}")
- end
- end
-
- end
-
- def writer_method(name, class_name, mapping, allow_nil, converter)
- module_eval do
- define_method("#{name}=") do |part|
- if part.nil? && allow_nil
- mapping.each { |pair| self[pair.first] = nil }
- instance_variable_set("@#{name}", nil)
- else
- unless part.is_a?(class_name.constantize) || converter.nil?
- part = case converter
- when Symbol
- class_name.constantize.send(converter, part)
- when Proc, Method
- converter.call(part)
- else
- raise ArgumentError, 'Converter must be a symbol denoting the converter method to call or a Proc to be invoked.'
- end
- end
- mapping.each { |pair| self[pair.first] = part.send(pair.last) }
- instance_variable_set("@#{name}", part.freeze)
- end
- end
- end
- end
- end
- end
-end
389 lib/active_record/association_preload.rb
View
@@ -1,389 +0,0 @@
-module ActiveRecord
- # See ActiveRecord::AssociationPreload::ClassMethods for documentation.
- module AssociationPreload #:nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
- # Implements the details of eager loading of ActiveRecord associations.
- # Application developers should not use this module directly.
- #
- # ActiveRecord::Base is extended with this module. The source code in
- # ActiveRecord::Base references methods defined in this module.
- #
- # Note that 'eager loading' and 'preloading' are actually the same thing.
- # However, there are two different eager loading strategies.
- #
- # The first one is by using table joins. This was only strategy available
- # prior to Rails 2.1. Suppose that you have an Author model with columns
- # 'name' and 'age', and a Book model with columns 'name' and 'sales'. Using
- # this strategy, ActiveRecord would try to retrieve all data for an author
- # and all of its books via a single query:
- #
- # SELECT * FROM authors
- # LEFT OUTER JOIN books ON authors.id = books.id
- # WHERE authors.name = 'Ken Akamatsu'
- #
- # However, this could result in many rows that contain redundant data. After
- # having received the first row, we already have enough data to instantiate
- # the Author object. In all subsequent rows, only the data for the joined
- # 'books' table is useful; the joined 'authors' data is just redundant, and
- # processing this redundant data takes memory and CPU time. The problem
- # quickly becomes worse and worse as the level of eager loading increases
- # (i.e. if ActiveRecord is to eager load the associations' assocations as
- # well).
- #
- # The second strategy is to use multiple database queries, one for each
- # level of association. Since Rails 2.1, this is the default strategy. In
- # situations where a table join is necessary (e.g. when the +:conditions+
- # option references an association's column), it will fallback to the table
- # join strategy.
- #
- # See also ActiveRecord::Associations::ClassMethods, which explains eager
- # loading in a more high-level (application developer-friendly) manner.
- module ClassMethods
- protected
-
- # Eager loads the named associations for the given ActiveRecord record(s).
- #
- # In this description, 'association name' shall refer to the name passed
- # to an association creation method. For example, a model that specifies
- # <tt>belongs_to :author</tt>, <tt>has_many :buyers</tt> has association
- # names +:author+ and +:buyers+.
- #
- # == Parameters
- # +records+ is an array of ActiveRecord::Base. This array needs not be flat,
- # i.e. +records+ itself may also contain arrays of records. In any case,
- # +preload_associations+ will preload the associations all records by
- # flattening +records+.
- #
- # +associations+ specifies one or more associations that you want to
- # preload. It may be:
- # - a Symbol or a String which specifies a single association name. For
- # example, specifiying +:books+ allows this method to preload all books
- # for an Author.
- # - an Array which specifies multiple association names. This array
- # is processed recursively. For example, specifying <tt>[:avatar, :books]</tt>
- # allows this method to preload an author's avatar as well as all of his
- # books.
- # - a Hash which specifies multiple association names, as well as
- # association names for the to-be-preloaded association objects. For
- # example, specifying <tt>{ :author => :avatar }</tt> will preload a
- # book's author, as well as that author's avatar.
- #
- # +:associations+ has the same format as the +:include+ option for
- # <tt>ActiveRecord::Base.find</tt>. So +associations+ could look like this:
- #
- # :books
- # [ :books, :author ]
- # { :author => :avatar }
- # [ :books, { :author => :avatar } ]
- #
- # +preload_options+ contains options that will be passed to ActiveRecord#find
- # (which is called under the hood for preloading records). But it is passed
- # only one level deep in the +associations+ argument, i.e. it's not passed
- # to the child associations when +associations+ is a Hash.
- def preload_associations(records, associations, preload_options={})
- records = [records].flatten.compact.uniq
- return if records.empty?
- case associations
- when Array then associations.each {|association| preload_associations(records, association, preload_options)}
- when Symbol, String then preload_one_association(records, associations.to_sym, preload_options)
- when Hash then
- associations.each do |parent, child|
- raise "parent must be an association name" unless parent.is_a?(String) || parent.is_a?(Symbol)
- preload_associations(records, parent, preload_options)
- reflection = reflections[parent]
- parents = records.map {|record| record.send(reflection.name)}.flatten.compact
- unless parents.empty?
- parents.first.class.preload_associations(parents, child)
- end
- end
- end
- end
-
- private
-
- # Preloads a specific named association for the given records. This is
- # called by +preload_associations+ as its base case.
- def preload_one_association(records, association, preload_options={})
- class_to_reflection = {}
- # Not all records have the same class, so group then preload
- # group on the reflection itself so that if various subclass share the same association then we do not split them
- # unnecessarily
- records.group_by {|record| class_to_reflection[record.class] ||= record.class.reflections[association]}.each do |reflection, records|
- raise ConfigurationError, "Association named '#{ association }' was not found; perhaps you misspelled it?" unless reflection
-
- # 'reflection.macro' can return 'belongs_to', 'has_many', etc. Thus,
- # the following could call 'preload_belongs_to_association',
- # 'preload_has_many_association', etc.
- send("preload_#{reflection.macro}_association", records, reflection, preload_options)
- end
- end
-
- def add_preloaded_records_to_collection(parent_records, reflection_name, associated_record)
- parent_records.each do |parent_record|
- association_proxy = parent_record.send(reflection_name)
- association_proxy.loaded
- association_proxy.target.push(*[associated_record].flatten)
- end
- end
-
- def add_preloaded_record_to_collection(parent_records, reflection_name, associated_record)
- parent_records.each do |parent_record|
- parent_record.send("set_#{reflection_name}_target", associated_record)
- end
- end
-
- def set_association_collection_records(id_to_record_map, reflection_name, associated_records, key)
- associated_records.each do |associated_record|
- mapped_records = id_to_record_map[associated_record[key].to_s]
- add_preloaded_records_to_collection(mapped_records, reflection_name, associated_record)
- end
- end
-
- def set_association_single_records(id_to_record_map, reflection_name, associated_records, key)
- seen_keys = {}
- associated_records.each do |associated_record|
- #this is a has_one or belongs_to: there should only be one record.
- #Unfortunately we can't (in portable way) ask the database for 'all records where foo_id in (x,y,z), but please
- # only one row per distinct foo_id' so this where we enforce that
- next if seen_keys[associated_record[key].to_s]
- seen_keys[associated_record[key].to_s] = true
- mapped_records = id_to_record_map[associated_record[key].to_s]
- mapped_records.each do |mapped_record|
- mapped_record.send("set_#{reflection_name}_target", associated_record)
- end
- end
- end
-
- # Given a collection of ActiveRecord objects, constructs a Hash which maps
- # the objects' IDs to the relevant objects. Returns a 2-tuple
- # <tt>(id_to_record_map, ids)</tt> where +id_to_record_map+ is the Hash,
- # and +ids+ is an Array of record IDs.
- def construct_id_map(records, primary_key=nil)
- id_to_record_map = {}
- ids = []
- records.each do |record|
- primary_key ||= record.class.primary_key
- ids << record[primary_key]
- mapped_records = (id_to_record_map[ids.last.to_s] ||= [])
- mapped_records << record
- end
- ids.uniq!
- return id_to_record_map, ids
- end
-
- def preload_has_and_belongs_to_many_association(records, reflection, preload_options={})
- table_name = reflection.klass.quoted_table_name
- id_to_record_map, ids = construct_id_map(records)
- records.each {|record| record.send(reflection.name).loaded}
- options = reflection.options
-
- conditions = "t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}"
- conditions << append_conditions(reflection, preload_options)
-
- associated_records = reflection.klass.with_exclusive_scope do
- reflection.klass.find(:all, :conditions => [conditions, ids],
- :include => options[:include],
- :joins => "INNER JOIN #{connection.quote_table_name options[:join_table]} t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}",
- :select => "#{options[:select] || table_name+'.*'}, t0.#{reflection.primary_key_name} as the_parent_record_id",
- :order => options[:order])
- end
- set_association_collection_records(id_to_record_map, reflection.name, associated_records, 'the_parent_record_id')
- end
-
- def preload_has_one_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
- id_to_record_map, ids = construct_id_map(records, reflection.options[:primary_key])
- options = reflection.options
- records.each {|record| record.send("set_#{reflection.name}_target", nil)}
- if options[:through]
- through_records = preload_through_records(records, reflection, options[:through])
- through_reflection = reflections[options[:through]]
- through_primary_key = through_reflection.primary_key_name
- unless through_records.empty?
- source = reflection.source_reflection.name
- through_records.first.class.preload_associations(through_records, source)
- if through_reflection.macro == :belongs_to
- rev_id_to_record_map, rev_ids = construct_id_map(records, through_primary_key)
- rev_primary_key = through_reflection.klass.primary_key
- through_records.each do |through_record|
- add_preloaded_record_to_collection(rev_id_to_record_map[through_record[rev_primary_key].to_s],
- reflection.name, through_record.send(source))
- end
- else
- through_records.each do |through_record|
- add_preloaded_record_to_collection(id_to_record_map[through_record[through_primary_key].to_s],
- reflection.name, through_record.send(source))
- end
- end
- end
- else
- set_association_single_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options), reflection.primary_key_name)
- end
- end
-
- def preload_has_many_association(records, reflection, preload_options={})
- return if records.first.send(reflection.name).loaded?
- options = reflection.options
-
- primary_key_name = reflection.through_reflection_primary_key_name
- id_to_record_map, ids = construct_id_map(records, primary_key_name || reflection.options[:primary_key])
- records.each {|record| record.send(reflection.name).loaded}
-
- if options[:through]
- through_records = preload_through_records(records, reflection, options[:through])
- through_reflection = reflections[options[:through]]
- unless through_records.empty?
- source = reflection.source_reflection.name
- through_records.first.class.preload_associations(through_records, source, options)
- through_records.each do |through_record|
- through_record_id = through_record[reflection.through_reflection_primary_key].to_s
- add_preloaded_records_to_collection(id_to_record_map[through_record_id], reflection.name, through_record.send(source))
- end
- end
-
- else
- set_association_collection_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options),
- reflection.primary_key_name)
- end
- end
-
- def preload_through_records(records, reflection, through_association)
- through_reflection = reflections[through_association]
- through_primary_key = through_reflection.primary_key_name
-
- if reflection.options[:source_type]
- interface = reflection.source_reflection.options[:foreign_type]
- preload_options = {:conditions => ["#{connection.quote_column_name interface} = ?", reflection.options[:source_type]]}
-
- records.compact!
- records.first.class.preload_associations(records, through_association, preload_options)
-
- # Dont cache the association - we would only be caching a subset
- through_records = []
- records.each do |record|
- proxy = record.send(through_association)
-
- if proxy.respond_to?(:target)
- through_records << proxy.target
- proxy.reset
- else # this is a has_one :through reflection
- through_records << proxy if proxy
- end
- end
- through_records.flatten!
- else
- records.first.class.preload_associations(records, through_association)
- through_records = records.map {|record| record.send(through_association)}.flatten
- end
- through_records.compact!
- through_records
- end
-
- def preload_belongs_to_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
- options = reflection.options
- primary_key_name = reflection.primary_key_name
-
- if options[:polymorphic]
- polymorph_type = options[:foreign_type]
- klasses_and_ids = {}
-
- # Construct a mapping from klass to a list of ids to load and a mapping of those ids back to their parent_records
- records.each do |record|
- if klass = record.send(polymorph_type)
- klass_id = record.send(primary_key_name)
- if klass_id
- id_map = klasses_and_ids[klass] ||= {}
- id_list_for_klass_id = (id_map[klass_id.to_s] ||= [])
- id_list_for_klass_id << record
- end
- end
- end
- klasses_and_ids = klasses_and_ids.to_a
- else
- id_map = {}
- records.each do |record|
- key = record.send(primary_key_name)
- if key
- mapped_records = (id_map[key.to_s] ||= [])
- mapped_records << record
- end
- end
- klasses_and_ids = [[reflection.klass.name, id_map]]
- end
-
- klasses_and_ids.each do |klass_and_id|
- klass_name, id_map = *klass_and_id
- next if id_map.empty?
- klass = klass_name.constantize
-
- table_name = klass.quoted_table_name
- primary_key = klass.primary_key
- column_type = klass.columns.detect{|c| c.name == primary_key}.type
- ids = id_map.keys.map do |id|
- if column_type == :integer
- id.to_i
- elsif column_type == :float
- id.to_f
- else
- id
- end
- end
- conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}"
- conditions << append_conditions(reflection, preload_options)
- associated_records = klass.with_exclusive_scope do
- klass.find(:all, :conditions => [conditions, ids],
- :include => options[:include],
- :select => options[:select],
- :joins => options[:joins],
- :order => options[:order])
- end
- set_association_single_records(id_map, reflection.name, associated_records, primary_key)
- end
- end
-
- def find_associated_records(ids, reflection, preload_options)
- options = reflection.options
- table_name = reflection.klass.quoted_table_name
-
- if interface = reflection.options[:as]
- conditions = "#{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_id"} #{in_or_equals_for_ids(ids)} and #{reflection.klass.quoted_table_name}.#{connection.quote_column_name "#{interface}_type"} = '#{self.base_class.sti_name}'"
- else
- foreign_key = reflection.primary_key_name
- conditions = "#{reflection.klass.quoted_table_name}.#{foreign_key} #{in_or_equals_for_ids(ids)}"
- end
-
- conditions << append_conditions(reflection, preload_options)
-
- reflection.klass.with_exclusive_scope do
- reflection.klass.find(:all,
- :select => (preload_options[:select] || options[:select] || "#{table_name}.*"),
- :include => preload_options[:include] || options[:include],
- :conditions => [conditions, ids],
- :joins => options[:joins],
- :group => preload_options[:group] || options[:group],
- :order => preload_options[:order] || options[:order])
- end
- end
-
-
- def interpolate_sql_for_preload(sql)
- instance_eval("%@#{sql.gsub('@', '\@')}@")
- end
-
- def append_conditions(reflection, preload_options)
- sql = ""
- sql << " AND (#{interpolate_sql_for_preload(reflection.sanitized_conditions)})" if reflection.sanitized_conditions
- sql << " AND (#{sanitize_sql preload_options[:conditions]})" if preload_options[:conditions]
- sql
- end
-
- def in_or_equals_for_ids(ids)
- ids.size > 1 ? "IN (?)" : "= ?"
- end
- end
- end
-end
2,241 lib/active_record/associations.rb
View
0 additions, 2,241 deletions not shown
475 lib/active_record/associations/association_collection.rb
View
@@ -1,475 +0,0 @@
-require 'set'
-
-module ActiveRecord
- module Associations
- # AssociationCollection is an abstract class that provides common stuff to
- # ease the implementation of association proxies that represent
- # collections. See the class hierarchy in AssociationProxy.
- #
- # You need to be careful with assumptions regarding the target: The proxy
- # does not fetch records from the database until it needs them, but new
- # ones created with +build+ are added to the target. So, the target may be
- # non-empty and still lack children waiting to be read from the database.
- # If you look directly to the database you cannot assume that's the entire
- # collection because new records may have beed added to the target, etc.
- #
- # If you need to work on all current children, new and existing records,
- # +load_target+ and the +loaded+ flag are your friends.
- class AssociationCollection < AssociationProxy #:nodoc:
- def initialize(owner, reflection)
- super
- construct_sql
- end
-
- def find(*args)
- options = args.extract_options!
-
- # If using a custom finder_sql, scan the entire collection.
- if @reflection.options[:finder_sql]
- expects_array = args.first.kind_of?(Array)
- ids = args.flatten.compact.uniq.map { |arg| arg.to_i }
-
- if ids.size == 1
- id = ids.first
- record = load_target.detect { |r| id == r.id }
- expects_array ? [ record ] : record
- else
- load_target.select { |r| ids.include?(r.id) }
- end
- else
- conditions = "#{@finder_sql}"
- if sanitized_conditions = sanitize_sql(options[:conditions])
- conditions << " AND (#{sanitized_conditions})"
- end
-
- options[:conditions] = conditions
-
- if options[:order] && @reflection.options[:order]
- options[:order] = "#{options[:order]}, #{@reflection.options[:order]}"
- elsif @reflection.options[:order]
- options[:order] = @reflection.options[:order]
- end
-
- # Build options specific to association
- construct_find_options!(options)
-
- merge_options_from_reflection!(options)
-
- # Pass through args exactly as we received them.
- args << options
- @reflection.klass.find(*args)
- end
- end
-
- # Fetches the first one using SQL if possible.
- def first(*args)
- if fetch_first_or_last_using_find?(args)
- find(:first, *args)
- else
- load_target unless loaded?
- @target.first(*args)
- end
- end
-
- # Fetches the last one using SQL if possible.
- def last(*args)
- if fetch_first_or_last_using_find?(args)
- find(:last, *args)
- else
- load_target unless loaded?
- @target.last(*args)
- end
- end
-
- def to_ary
- load_target
- if @target.is_a?(Array)
- @target.to_ary
- else
- Array(@target)
- end
- end
-
- def reset
- reset_target!
- @loaded = false
- end
-
- def build(attributes = {}, &block)
- if attributes.is_a?(Array)
- attributes.collect { |attr| build(attr, &block) }
- else
- build_record(attributes) do |record|
- block.call(record) if block_given?
- set_belongs_to_association_for(record)
- end
- end
- end
-
- # Add +records+ to this association. Returns +self+ so method calls may be chained.
- # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
- def <<(*records)
- result = true
- load_target if @owner.new_record?
-
- transaction do
- flatten_deeper(records).each do |record|
- raise_on_type_mismatch(record)
- add_record_to_target_with_callbacks(record) do |r|
- result &&= insert_record(record) unless @owner.new_record?
- end
- end
- end
-
- result && self
- end
-
- alias_method :push, :<<
- alias_method :concat, :<<
-
- # Starts a transaction in the association class's database connection.
- #
- # class Author < ActiveRecord::Base
- # has_many :books
- # end
- #
- # Author.find(:first).books.transaction do
- # # same effect as calling Book.transaction
- # end
- def transaction(*args)
- @reflection.klass.transaction(*args) do
- yield
- end
- end
-
- # Remove all records from this association
- #
- # See delete for more info.
- def delete_all
- load_target
- delete(@target)
- reset_target!
- end
-
- # Calculate sum using SQL, not Enumerable
- def sum(*args)
- if block_given?
- calculate(:sum, *args) { |*block_args| yield(*block_args) }
- else
- calculate(:sum, *args)
- end
- end
-
- # Count all records using SQL. If the +:counter_sql+ option is set for the association, it will
- # be used for the query. If no +:counter_sql+ was supplied, but +:finder_sql+ was set, the
- # descendant's +construct_sql+ method will have set :counter_sql automatically.
- # Otherwise, construct options and pass them with scope to the target class's +count+.
- def count(*args)
- if @reflection.options[:counter_sql]
- @reflection.klass.count_by_sql(@counter_sql)
- else
- column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
- if @reflection.options[:uniq]
- # This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL.
- column_name = "#{@reflection.quoted_table_name}.#{@reflection.klass.primary_key}" if column_name == :all
- options.merge!(:distinct => true)
- end
-
- value = @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) }
-
- limit = @reflection.options[:limit]
- offset = @reflection.options[:offset]
-
- if limit || offset
- [ [value - offset.to_i, 0].max, limit.to_i ].min
- else
- value
- end
- end
- end
-
- # Removes +records+ from this association calling +before_remove+ and
- # +after_remove+ callbacks.
- #
- # This method is abstract in the sense that +delete_records+ has to be
- # provided by descendants. Note this method does not imply the records
- # are actually removed from the database, that depends precisely on
- # +delete_records+. They are in any case removed from the collection.
- def delete(*records)
- remove_records(records) do |records, old_records|
- delete_records(old_records) if old_records.any?
- records.each { |record| @target.delete(record) }
- end
- end
-
- # Destroy +records+ and remove them from this association calling
- # +before_remove+ and +after_remove+ callbacks.
- #
- # Note that this method will _always_ remove records from the database
- # ignoring the +:dependent+ option.
- def destroy(*records)
- records = find(records) if records.any? {|record| record.kind_of?(Fixnum) || record.kind_of?(String)}
- remove_records(records) do |records, old_records|
- old_records.each { |record| record.destroy }
- end
-
- load_target
- end
-
- # Removes all records from this association. Returns +self+ so method calls may be chained.
- def clear
- return self if length.zero? # forces load_target if it hasn't happened already
-
- if @reflection.options[:dependent] && @reflection.options[:dependent] == :destroy
- destroy_all
- else
- delete_all
- end
-
- self
- end
-
- # Destory all the records from this association.
- #
- # See destroy for more info.
- def destroy_all
- load_target
- destroy(@target)
- reset_target!
- end
-
- def create(attrs = {})
- if attrs.is_a?(Array)
- attrs.collect { |attr| create(attr) }
- else
- create_record(attrs) do |record|
- yield(record) if block_given?
- record.save
- end
- end
- end
-
- def create!(attrs = {})
- create_record(attrs) do |record|
- yield(record) if block_given?
- record.save!
- end
- end
-
- # Returns the size of the collection by executing a SELECT COUNT(*)
- # query if the collection hasn't been loaded, and calling
- # <tt>collection.size</tt> if it has.
- #
- # If the collection has been already loaded +size+ and +length+ are
- # equivalent. If not and you are going to need the records anyway
- # +length+ will take one less query. Otherwise +size+ is more efficient.
- #
- # This method is abstract in the sense that it relies on
- # +count_records+, which is a method descendants have to provide.
- def size
- if @owner.new_record? || (loaded? && !@reflection.options[:uniq])
- @target.size
- elsif !loaded? && @reflection.options[:group]
- load_target.size
- elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array)
- unsaved_records = @target.select { |r| r.new_record? }
- unsaved_records.size + count_records
- else
- count_records
- end
- end
-
- # Returns the size of the collection calling +size+ on the target.
- #
- # If the collection has been already loaded +length+ and +size+ are
- # equivalent. If not and you are going to need the records anyway this
- # method will take one less query. Otherwise +size+ is more efficient.
- def length
- load_target.size
- end
-
- # Equivalent to <tt>collection.size.zero?</tt>. If the collection has
- # not been already loaded and you are going to fetch the records anyway
- # it is better to check <tt>collection.length.zero?</tt>.
- def empty?
- size.zero?
- end
-
- def any?
- if block_given?
- method_missing(:any?) { |*block_args| yield(*block_args) }
- else
- !empty?
- end
- end
-
- def uniq(collection = self)
- seen = Set.new
- collection.inject([]) do |kept, record|
- unless seen.include?(record.id)
- kept << record
- seen << record.id
- end
- kept
- end
- end
-
- # Replace this collection with +other_array+
- # This will perform a diff and delete/add only records that have changed.
- def replace(other_array)
- other_array.each { |val| raise_on_type_mismatch(val) }
-
- load_target
- other = other_array.size < 100 ? other_array : other_array.to_set
- current = @target.size < 100 ? @target : @target.to_set
-
- transaction do
- delete(@target.select { |v| !other.include?(v) })
- concat(other_array.select { |v| !current.include?(v) })
- end
- end
-
- def include?(record)
- return false unless record.is_a?(@reflection.klass)
- load_target if @reflection.options[:finder_sql] && !loaded?
- return @target.include?(record) if loaded?
- exists?(record)
- end
-
- def proxy_respond_to?(method, include_private = false)
- super || @reflection.klass.respond_to?(method, include_private)
- end
-
- protected
- def construct_find_options!(options)
- end
-
- def load_target
- if !@owner.new_record? || foreign_key_present
- begin
- if !loaded?
- if @target.is_a?(Array) && @target.any?
- @target = find_target + @target.find_all {|t| t.new_record? }
- else
- @target = find_target
- end
- end
- rescue ActiveRecord::RecordNotFound
- reset
- end
- end
-
- loaded if target
- target
- end
-
- def method_missing(method, *args)
- if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
- if block_given?
- super { |*block_args| yield(*block_args) }
- else
- super
- end
- elsif @reflection.klass.scopes.include?(method)
- @reflection.klass.scopes[method].call(self, *args)
- else
- with_scope(construct_scope) do
- if block_given?
- @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
- else
- @reflection.klass.send(method, *args)
- end
- end
- end
- end
-
- # overloaded in derived Association classes to provide useful scoping depending on association type.
- def construct_scope
- {}
- end
-
- def reset_target!
- @target = Array.new
- end
-
- def find_target
- records =
- if @reflection.options[:finder_sql]
- @reflection.klass.find_by_sql(@finder_sql)
- else
- find(:all)
- end
-
- @reflection.options[:uniq] ? uniq(records) : records
- end
-
- private
-
- def create_record(attrs)
- attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
- ensure_owner_is_not_new
- record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) do
- @reflection.build_association(attrs)
- end
- if block_given?
- add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) }
- else
- add_record_to_target_with_callbacks(record)
- end
- end
-
- def build_record(attrs)
- attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
- record = @reflection.build_association(attrs)
- if block_given?
- add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) }
- else
- add_record_to_target_with_callbacks(record)
- end
- end
-
- def add_record_to_target_with_callbacks(record)
- callback(:before_add, record)
- yield(record) if block_given?
- @target ||= [] unless loaded?
- @target << record unless @reflection.options[:uniq] && @target.include?(record)
- callback(:after_add, record)
- record
- end
-
- def remove_records(*records)
- records = flatten_deeper(records)
- records.each { |record| raise_on_type_mismatch(record) }
-
- transaction do
- records.each { |record| callback(:before_remove, record) }
- old_records = records.reject { |r| r.new_record? }
- yield(records, old_records)
- records.each { |record| callback(:after_remove, record) }
- end
- end
-
- def callback(method, record)
- callbacks_for(method).each do |callback|
- ActiveSupport::Callbacks::Callback.new(method, callback, record).call(@owner, record)
- end
- end
-
- def callbacks_for(callback_name)
- full_callback_name = "#{callback_name}_for_#{@reflection.name}"
- @owner.class.read_inheritable_attribute(full_callback_name.to_sym) || []
- end
-
- def ensure_owner_is_not_new
- if @owner.new_record?
- raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
- end
- end
-
- def fetch_first_or_last_using_find?(args)
- args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] ||
- @target.any? { |record| record.new_record? } || args.first.kind_of?(Integer))
- end
- end
- end
-end
278 lib/active_record/associations/association_proxy.rb
View
@@ -1,278 +0,0 @@
-module ActiveRecord
- module Associations
- # This is the root class of all association proxies:
- #
- # AssociationProxy
- # BelongsToAssociation
- # HasOneAssociation
- # BelongsToPolymorphicAssociation
- # AssociationCollection
- # HasAndBelongsToManyAssociation
- # HasManyAssociation
- # HasManyThroughAssociation
- # HasOneThroughAssociation
- #
- # Association proxies in Active Record are middlemen between the object that
- # holds the association, known as the <tt>@owner</tt>, and the actual associated
- # object, known as the <tt>@target</tt>. The kind of association any proxy is
- # about is available in <tt>@reflection</tt>. That's an instance of the class
- # ActiveRecord::Reflection::AssociationReflection.
- #
- # For example, given
- #
- # class Blog < ActiveRecord::Base
- # has_many :posts
- # end
- #
- # blog = Blog.find(:first)
- #
- # the association proxy in <tt>blog.posts</tt> has the object in +blog+ as
- # <tt>@owner</tt>, the collection of its posts as <tt>@target</tt>, and
- # the <tt>@reflection</tt> object represents a <tt>:has_many</tt> macro.
- #
- # This class has most of the basic instance methods removed, and delegates
- # unknown methods to <tt>@target</tt> via <tt>method_missing</tt>. As a
- # corner case, it even removes the +class+ method and that's why you get
- #
- # blog.posts.class # => Array
- #
- # though the object behind <tt>blog.posts</tt> is not an Array, but an
- # ActiveRecord::Associations::HasManyAssociation.
- #
- # The <tt>@target</tt> object is not \loaded until needed. For example,
- #
- # blog.posts.count
- #
- # is computed directly through SQL and does not trigger by itself the
- # instantiation of the actual post records.
- class AssociationProxy #:nodoc:
- alias_method :proxy_respond_to?, :respond_to?
- alias_method :proxy_extend, :extend
- delegate :to_param, :to => :proxy_target
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
-
- def initialize(owner, reflection)
- @owner, @reflection = owner, reflection
- Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
- reset
- end
-
- # Returns the owner of the proxy.
- def proxy_owner
- @owner
- end
-
- # Returns the reflection object that represents the association handled
- # by the proxy.
- def proxy_reflection
- @reflection
- end
-
- # Returns the \target of the proxy, same as +target+.
- def proxy_target
- @target
- end
-
- # Does the proxy or its \target respond to +symbol+?
- def respond_to?(*args)
- proxy_respond_to?(*args) || (load_target && @target.respond_to?(*args))
- end
-
- # Forwards <tt>===</tt> explicitly to the \target because the instance method
- # removal above doesn't catch it. Loads the \target if needed.
- def ===(other)
- load_target
- other === @target
- end
-
- # Returns the name of the table of the related class:
- #
- # post.comments.aliased_table_name # => "comments"
- #
- def aliased_table_name
- @reflection.klass.table_name
- end
-
- # Returns the SQL string that corresponds to the <tt>:conditions</tt>
- # option of the macro, if given, or +nil+ otherwise.
- def conditions
- @conditions ||= interpolate_sql(@reflection.sanitized_conditions) if @reflection.sanitized_conditions
- end
- alias :sql_conditions :conditions
-
- # Resets the \loaded flag to +false+ and sets the \target to +nil+.
- def reset
- @loaded = false
- @target = nil
- end
-
- # Reloads the \target and returns +self+ on success.
- def reload
- reset
- load_target
- self unless @target.nil?
- end
-
- # Has the \target been already \loaded?
- def loaded?
- @loaded
- end
-
- # Asserts the \target has been loaded setting the \loaded flag to +true+.
- def loaded
- @loaded = true
- end
-
- # Returns the target of this proxy, same as +proxy_target+.
- def target
- @target
- end
-
- # Sets the target of this proxy to <tt>\target</tt>, and the \loaded flag to +true+.
- def target=(target)
- @target = target
- loaded
- end
-
- # Forwards the call to the target. Loads the \target if needed.
- def inspect
- load_target
- @target.inspect
- end
-
- def send(method, *args)
- if proxy_respond_to?(method)
- super
- else
- load_target
- @target.send(method, *args)
- end
- end
-
- protected
- # Does the association have a <tt>:dependent</tt> option?
- def dependent?
- @reflection.options[:dependent]
- end
-
- # Returns a string with the IDs of +records+ joined with a comma, quoted
- # if needed. The result is ready to be inserted into a SQL IN clause.
- #
- # quoted_record_ids(records) # => "23,56,58,67"
- #
- def quoted_record_ids(records)
- records.map { |record| record.quoted_id }.join(',')
- end
-
- def interpolate_sql(sql, record = nil)
- @owner.send(:interpolate_sql, sql, record)
- end
-
- # Forwards the call to the reflection class.
- def sanitize_sql(sql, table_name = @reflection.klass.quoted_table_name)
- @reflection.klass.send(:sanitize_sql, sql, table_name)
- end
-
- # Assigns the ID of the owner to the corresponding foreign key in +record+.
- # If the association is polymorphic the type of the owner is also set.
- def set_belongs_to_association_for(record)
- if @reflection.options[:as]
- record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
- record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s
- else
- unless @owner.new_record?
- primary_key = @reflection.options[:primary_key] || :id
- record[@reflection.primary_key_name] = @owner.send(primary_key)
- end
- end
- end
-
- # Merges into +options+ the ones coming from the reflection.
- def merge_options_from_reflection!(options)
- options.reverse_merge!(
- :group => @reflection.options[:group],
- :having => @reflection.options[:having],
- :limit => @reflection.options[:limit],
- :offset => @reflection.options[:offset],
- :joins => @reflection.options[:joins],
- :include => @reflection.options[:include],
- :select => @reflection.options[:select],
- :readonly => @reflection.options[:readonly]
- )
- end
-
- # Forwards +with_scope+ to the reflection.
- def with_scope(*args, &block)
- @reflection.klass.send :with_scope, *args, &block
- end
-
- private
- # Forwards any missing method call to the \target.
- def method_missing(method, *args)
- if load_target
- if @target.respond_to?(method)
- if block_given?
- @target.send(method, *args) { |*block_args| yield(*block_args) }
- else
- @target.send(method, *args)
- end
- else
- super
- end
- end
- end
-
- # Loads the \target if needed and returns it.
- #
- # This method is abstract in the sense that it relies on +find_target+,
- # which is expected to be provided by descendants.
- #
- # If the \target is already \loaded it is just returned. Thus, you can call
- # +load_target+ unconditionally to get the \target.
- #
- # ActiveRecord::RecordNotFound is rescued within the method, and it is