sunspot_rails 2.0.0.pre.120924 → 2.0.0.pre.120925
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -10
- data/{sunspot_rails/.rspec → .rspec} +0 -0
- data/{sunspot_rails/History.txt → History.txt} +0 -0
- data/{sunspot/LICENSE → LICENSE} +0 -0
- data/{sunspot_rails/MIT-LICENSE → MIT-LICENSE} +0 -0
- data/{sunspot_rails/README.rdoc → README.rdoc} +0 -0
- data/Rakefile +12 -32
- data/{sunspot_rails/TODO → TODO} +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/rdoc.rake +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/release.rake +0 -0
- data/{sunspot_rails/dev_tasks → dev_tasks}/spec.rake +0 -0
- data/{sunspot/tasks → dev_tasks}/todo.rake +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-2.3.14 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.0.15 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.1.6 +0 -0
- data/{sunspot_rails/gemfiles → gemfiles}/rails-3.2.6 +0 -0
- data/{sunspot_rails/generators → generators}/sunspot/sunspot_generator.rb +0 -0
- data/{sunspot_rails/generators → generators}/sunspot/templates/sunspot.yml +0 -0
- data/{sunspot_rails/install.rb → install.rb} +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails.rb +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails/install/install_generator.rb +0 -0
- data/{sunspot_rails/lib → lib}/generators/sunspot_rails/install/templates/config/sunspot.yml +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/adapters.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/configuration.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/init.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/log_subscriber.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/railtie.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/railties/controller_runtime.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/request_lifecycle.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/searchable.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/server.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/solr_instrumentation.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/solr_logging.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/spec_helper.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/stub_session_proxy.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot/rails/tasks.rb +0 -0
- data/{sunspot_rails/lib → lib}/sunspot_rails.rb +0 -0
- data/{sunspot_rails/spec → spec}/configuration_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/model_lifecycle_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/model_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/controllers/application_controller.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/controllers/posts_controller.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/author.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/blog.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/location.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/photo_post.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post_with_auto.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/app/models/post_with_default_scope.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/boot.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/preinitializer.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/routes.rb +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/config/sunspot.yml +0 -0
- data/{sunspot_rails/spec → spec}/rails_template/db/schema.rb +0 -0
- data/{sunspot_rails/spec → spec}/request_lifecycle_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/schema.rb +0 -0
- data/{sunspot_rails/spec → spec}/searchable_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/server_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/session_spec.rb +0 -0
- data/{sunspot_rails/spec → spec}/shared_examples/indexed_after_save.rb +0 -0
- data/{sunspot_rails/spec → spec}/shared_examples/not_indexed_after_save.rb +0 -0
- data/{sunspot_rails/spec → spec}/spec_helper.rb +0 -0
- data/{sunspot_rails/spec → spec}/stub_session_proxy_spec.rb +0 -0
- data/{sunspot_rails/sunspot_rails.gemspec → sunspot_rails.gemspec} +0 -0
- metadata +102 -305
- data/.travis.yml +0 -35
- data/README.md +0 -863
- data/ci/travis.sh +0 -67
- data/sunspot/.gitignore +0 -13
- data/sunspot/Gemfile +0 -5
- data/sunspot/History.txt +0 -258
- data/sunspot/Rakefile +0 -13
- data/sunspot/TODO +0 -13
- data/sunspot/lib/light_config.rb +0 -40
- data/sunspot/lib/sunspot.rb +0 -579
- data/sunspot/lib/sunspot/adapters.rb +0 -349
- data/sunspot/lib/sunspot/batcher.rb +0 -62
- data/sunspot/lib/sunspot/class_set.rb +0 -23
- data/sunspot/lib/sunspot/composite_setup.rb +0 -202
- data/sunspot/lib/sunspot/configuration.rb +0 -53
- data/sunspot/lib/sunspot/data_extractor.rb +0 -50
- data/sunspot/lib/sunspot/dsl.rb +0 -5
- data/sunspot/lib/sunspot/dsl/adjustable.rb +0 -47
- data/sunspot/lib/sunspot/dsl/field_group.rb +0 -57
- data/sunspot/lib/sunspot/dsl/field_query.rb +0 -345
- data/sunspot/lib/sunspot/dsl/fields.rb +0 -103
- data/sunspot/lib/sunspot/dsl/fulltext.rb +0 -243
- data/sunspot/lib/sunspot/dsl/function.rb +0 -27
- data/sunspot/lib/sunspot/dsl/functional.rb +0 -44
- data/sunspot/lib/sunspot/dsl/more_like_this_query.rb +0 -56
- data/sunspot/lib/sunspot/dsl/paginatable.rb +0 -32
- data/sunspot/lib/sunspot/dsl/query_facet.rb +0 -36
- data/sunspot/lib/sunspot/dsl/restriction.rb +0 -25
- data/sunspot/lib/sunspot/dsl/restriction_with_near.rb +0 -160
- data/sunspot/lib/sunspot/dsl/scope.rb +0 -214
- data/sunspot/lib/sunspot/dsl/search.rb +0 -30
- data/sunspot/lib/sunspot/dsl/standard_query.rb +0 -122
- data/sunspot/lib/sunspot/field.rb +0 -193
- data/sunspot/lib/sunspot/field_factory.rb +0 -129
- data/sunspot/lib/sunspot/indexer.rb +0 -136
- data/sunspot/lib/sunspot/query.rb +0 -11
- data/sunspot/lib/sunspot/query/abstract_field_facet.rb +0 -55
- data/sunspot/lib/sunspot/query/bbox.rb +0 -15
- data/sunspot/lib/sunspot/query/boost_query.rb +0 -24
- data/sunspot/lib/sunspot/query/common_query.rb +0 -96
- data/sunspot/lib/sunspot/query/composite_fulltext.rb +0 -36
- data/sunspot/lib/sunspot/query/connective.rb +0 -206
- data/sunspot/lib/sunspot/query/date_field_facet.rb +0 -14
- data/sunspot/lib/sunspot/query/dismax.rb +0 -132
- data/sunspot/lib/sunspot/query/field_facet.rb +0 -41
- data/sunspot/lib/sunspot/query/field_group.rb +0 -37
- data/sunspot/lib/sunspot/query/filter.rb +0 -38
- data/sunspot/lib/sunspot/query/function_query.rb +0 -52
- data/sunspot/lib/sunspot/query/geo.rb +0 -53
- data/sunspot/lib/sunspot/query/geofilt.rb +0 -16
- data/sunspot/lib/sunspot/query/highlighting.rb +0 -62
- data/sunspot/lib/sunspot/query/more_like_this.rb +0 -61
- data/sunspot/lib/sunspot/query/more_like_this_query.rb +0 -12
- data/sunspot/lib/sunspot/query/pagination.rb +0 -42
- data/sunspot/lib/sunspot/query/query_facet.rb +0 -53
- data/sunspot/lib/sunspot/query/range_facet.rb +0 -15
- data/sunspot/lib/sunspot/query/restriction.rb +0 -308
- data/sunspot/lib/sunspot/query/scope.rb +0 -9
- data/sunspot/lib/sunspot/query/sort.rb +0 -109
- data/sunspot/lib/sunspot/query/sort_composite.rb +0 -34
- data/sunspot/lib/sunspot/query/standard_query.rb +0 -16
- data/sunspot/lib/sunspot/query/text_field_boost.rb +0 -17
- data/sunspot/lib/sunspot/schema.rb +0 -151
- data/sunspot/lib/sunspot/search.rb +0 -9
- data/sunspot/lib/sunspot/search/abstract_search.rb +0 -286
- data/sunspot/lib/sunspot/search/date_facet.rb +0 -35
- data/sunspot/lib/sunspot/search/facet_row.rb +0 -27
- data/sunspot/lib/sunspot/search/field_facet.rb +0 -88
- data/sunspot/lib/sunspot/search/field_group.rb +0 -70
- data/sunspot/lib/sunspot/search/group.rb +0 -54
- data/sunspot/lib/sunspot/search/highlight.rb +0 -38
- data/sunspot/lib/sunspot/search/hit.rb +0 -150
- data/sunspot/lib/sunspot/search/hit_enumerable.rb +0 -68
- data/sunspot/lib/sunspot/search/more_like_this_search.rb +0 -31
- data/sunspot/lib/sunspot/search/paginated_collection.rb +0 -57
- data/sunspot/lib/sunspot/search/query_facet.rb +0 -67
- data/sunspot/lib/sunspot/search/range_facet.rb +0 -37
- data/sunspot/lib/sunspot/search/standard_search.rb +0 -21
- data/sunspot/lib/sunspot/session.rb +0 -262
- data/sunspot/lib/sunspot/session_proxy.rb +0 -95
- data/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb +0 -29
- data/sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +0 -66
- data/sunspot/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +0 -89
- data/sunspot/lib/sunspot/session_proxy/master_slave_session_proxy.rb +0 -43
- data/sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +0 -67
- data/sunspot/lib/sunspot/session_proxy/sharding_session_proxy.rb +0 -222
- data/sunspot/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +0 -42
- data/sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb +0 -37
- data/sunspot/lib/sunspot/setup.rb +0 -350
- data/sunspot/lib/sunspot/text_field_setup.rb +0 -29
- data/sunspot/lib/sunspot/type.rb +0 -393
- data/sunspot/lib/sunspot/util.rb +0 -252
- data/sunspot/lib/sunspot/version.rb +0 -3
- data/sunspot/script/console +0 -10
- data/sunspot/spec/api/adapters_spec.rb +0 -68
- data/sunspot/spec/api/batcher_spec.rb +0 -112
- data/sunspot/spec/api/binding_spec.rb +0 -50
- data/sunspot/spec/api/class_set_spec.rb +0 -24
- data/sunspot/spec/api/hit_enumerable_spec.rb +0 -47
- data/sunspot/spec/api/indexer/attributes_spec.rb +0 -149
- data/sunspot/spec/api/indexer/batch_spec.rb +0 -72
- data/sunspot/spec/api/indexer/dynamic_fields_spec.rb +0 -42
- data/sunspot/spec/api/indexer/fixed_fields_spec.rb +0 -57
- data/sunspot/spec/api/indexer/fulltext_spec.rb +0 -43
- data/sunspot/spec/api/indexer/removal_spec.rb +0 -53
- data/sunspot/spec/api/indexer/spec_helper.rb +0 -1
- data/sunspot/spec/api/indexer_spec.rb +0 -14
- data/sunspot/spec/api/query/advanced_manipulation_examples.rb +0 -35
- data/sunspot/spec/api/query/connectives_examples.rb +0 -201
- data/sunspot/spec/api/query/dsl_spec.rb +0 -18
- data/sunspot/spec/api/query/dynamic_fields_examples.rb +0 -165
- data/sunspot/spec/api/query/faceting_examples.rb +0 -497
- data/sunspot/spec/api/query/fulltext_examples.rb +0 -313
- data/sunspot/spec/api/query/function_spec.rb +0 -79
- data/sunspot/spec/api/query/geo_examples.rb +0 -68
- data/sunspot/spec/api/query/group_spec.rb +0 -32
- data/sunspot/spec/api/query/highlighting_examples.rb +0 -245
- data/sunspot/spec/api/query/more_like_this_spec.rb +0 -140
- data/sunspot/spec/api/query/ordering_pagination_examples.rb +0 -116
- data/sunspot/spec/api/query/scope_examples.rb +0 -275
- data/sunspot/spec/api/query/spatial_examples.rb +0 -27
- data/sunspot/spec/api/query/spec_helper.rb +0 -1
- data/sunspot/spec/api/query/standard_spec.rb +0 -29
- data/sunspot/spec/api/query/text_field_scoping_examples.rb +0 -30
- data/sunspot/spec/api/query/types_spec.rb +0 -20
- data/sunspot/spec/api/search/dynamic_fields_spec.rb +0 -33
- data/sunspot/spec/api/search/faceting_spec.rb +0 -360
- data/sunspot/spec/api/search/highlighting_spec.rb +0 -69
- data/sunspot/spec/api/search/hits_spec.rb +0 -147
- data/sunspot/spec/api/search/paginated_collection_spec.rb +0 -36
- data/sunspot/spec/api/search/results_spec.rb +0 -72
- data/sunspot/spec/api/search/search_spec.rb +0 -23
- data/sunspot/spec/api/search/spec_helper.rb +0 -1
- data/sunspot/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +0 -85
- data/sunspot/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +0 -30
- data/sunspot/spec/api/session_proxy/master_slave_session_proxy_spec.rb +0 -41
- data/sunspot/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +0 -78
- data/sunspot/spec/api/session_proxy/sharding_session_proxy_spec.rb +0 -77
- data/sunspot/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +0 -24
- data/sunspot/spec/api/session_proxy/spec_helper.rb +0 -9
- data/sunspot/spec/api/session_proxy/thread_local_session_proxy_spec.rb +0 -39
- data/sunspot/spec/api/session_spec.rb +0 -232
- data/sunspot/spec/api/spec_helper.rb +0 -3
- data/sunspot/spec/api/sunspot_spec.rb +0 -29
- data/sunspot/spec/ext.rb +0 -11
- data/sunspot/spec/helpers/indexer_helper.rb +0 -17
- data/sunspot/spec/helpers/integration_helper.rb +0 -8
- data/sunspot/spec/helpers/mock_session_helper.rb +0 -13
- data/sunspot/spec/helpers/query_helper.rb +0 -26
- data/sunspot/spec/helpers/search_helper.rb +0 -68
- data/sunspot/spec/integration/dynamic_fields_spec.rb +0 -57
- data/sunspot/spec/integration/faceting_spec.rb +0 -330
- data/sunspot/spec/integration/field_grouping_spec.rb +0 -100
- data/sunspot/spec/integration/geospatial_spec.rb +0 -96
- data/sunspot/spec/integration/highlighting_spec.rb +0 -44
- data/sunspot/spec/integration/indexing_spec.rb +0 -55
- data/sunspot/spec/integration/keyword_search_spec.rb +0 -317
- data/sunspot/spec/integration/local_search_spec.rb +0 -64
- data/sunspot/spec/integration/more_like_this_spec.rb +0 -43
- data/sunspot/spec/integration/scoped_search_spec.rb +0 -386
- data/sunspot/spec/integration/stored_fields_spec.rb +0 -12
- data/sunspot/spec/integration/test_pagination.rb +0 -43
- data/sunspot/spec/integration/unicode_spec.rb +0 -15
- data/sunspot/spec/mocks/adapters.rb +0 -33
- data/sunspot/spec/mocks/blog.rb +0 -3
- data/sunspot/spec/mocks/comment.rb +0 -21
- data/sunspot/spec/mocks/connection.rb +0 -126
- data/sunspot/spec/mocks/mock_adapter.rb +0 -30
- data/sunspot/spec/mocks/mock_class_sharding_session_proxy.rb +0 -24
- data/sunspot/spec/mocks/mock_record.rb +0 -52
- data/sunspot/spec/mocks/mock_sharding_session_proxy.rb +0 -15
- data/sunspot/spec/mocks/photo.rb +0 -11
- data/sunspot/spec/mocks/post.rb +0 -86
- data/sunspot/spec/mocks/super_class.rb +0 -2
- data/sunspot/spec/mocks/user.rb +0 -13
- data/sunspot/spec/spec_helper.rb +0 -40
- data/sunspot/sunspot.gemspec +0 -37
- data/sunspot/tasks/rdoc.rake +0 -27
- data/sunspot/tasks/schema.rake +0 -19
- data/sunspot_rails/.gitignore +0 -7
- data/sunspot_rails/LICENSE +0 -18
- data/sunspot_rails/Rakefile +0 -17
- data/sunspot_rails/dev_tasks/todo.rake +0 -4
- data/sunspot_solr/Gemfile +0 -3
- data/sunspot_solr/README.rdoc +0 -24
- data/sunspot_solr/bin/sunspot-installer +0 -20
- data/sunspot_solr/bin/sunspot-solr +0 -80
- data/sunspot_solr/lib/sunspot/solr/installer.rb +0 -25
- data/sunspot_solr/lib/sunspot/solr/installer/config_installer.rb +0 -46
- data/sunspot_solr/lib/sunspot/solr/installer/task_helper.rb +0 -13
- data/sunspot_solr/lib/sunspot/solr/java.rb +0 -10
- data/sunspot_solr/lib/sunspot/solr/railtie.rb +0 -15
- data/sunspot_solr/lib/sunspot/solr/server.rb +0 -223
- data/sunspot_solr/lib/sunspot/solr/tasks.rb +0 -49
- data/sunspot_solr/lib/sunspot_solr.rb +0 -5
- data/sunspot_solr/solr/README.txt +0 -42
- data/sunspot_solr/solr/etc/jetty.xml +0 -219
- data/sunspot_solr/solr/etc/webdefault.xml +0 -379
- data/sunspot_solr/solr/lib/jetty-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jetty-util-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/servlet-api-2.5-20081211.jar +0 -0
- data/sunspot_solr/solr/solr/.gitignore +0 -1
- data/sunspot_solr/solr/solr/README.txt +0 -54
- data/sunspot_solr/solr/solr/conf/admin-extra.html +0 -31
- data/sunspot_solr/solr/solr/conf/elevate.xml +0 -36
- data/sunspot_solr/solr/solr/conf/mapping-ISOLatin1Accent.txt +0 -246
- data/sunspot_solr/solr/solr/conf/protwords.txt +0 -21
- data/sunspot_solr/solr/solr/conf/schema.xml +0 -250
- data/sunspot_solr/solr/solr/conf/scripts.conf +0 -24
- data/sunspot_solr/solr/solr/conf/solrconfig.xml +0 -934
- data/sunspot_solr/solr/solr/conf/spellings.txt +0 -2
- data/sunspot_solr/solr/solr/conf/stopwords.txt +0 -58
- data/sunspot_solr/solr/solr/conf/synonyms.txt +0 -31
- data/sunspot_solr/solr/solr/conf/xslt/example.xsl +0 -132
- data/sunspot_solr/solr/solr/conf/xslt/example_atom.xsl +0 -67
- data/sunspot_solr/solr/solr/conf/xslt/example_rss.xsl +0 -66
- data/sunspot_solr/solr/solr/conf/xslt/luke.xsl +0 -337
- data/sunspot_solr/solr/start.jar +0 -0
- data/sunspot_solr/solr/webapps/solr.war +0 -0
- data/sunspot_solr/spec/server_spec.rb +0 -98
- data/sunspot_solr/spec/spec_helper.rb +0 -18
- data/sunspot_solr/sunspot_solr.gemspec +0 -37
- data/tools/gem_tasks.rb +0 -69
@@ -1,349 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# Sunspot works by saving references to the primary key (or natural ID) of
|
4
|
-
# each indexed object, and then retrieving the objects from persistent storage
|
5
|
-
# when their IDs are referenced in search results. In order for Sunspot to
|
6
|
-
# know what an object's primary key is, and how to retrieve objects from
|
7
|
-
# persistent storage given a primary key, an adapter must be registered for
|
8
|
-
# that object's class or one of its superclasses (for instance, an adapter
|
9
|
-
# registered for ActiveRecord::Base would be used for all ActiveRecord
|
10
|
-
# models).
|
11
|
-
#
|
12
|
-
# To provide Sunspot with this ability, adapters must have two roles:
|
13
|
-
#
|
14
|
-
# Data accessor::
|
15
|
-
# A subclass of Sunspot::Adapters::DataAccessor, this object is instantiated
|
16
|
-
# with a particular class and must respond to the #load() method, which
|
17
|
-
# returns an object from persistent storage given that object's primary key.
|
18
|
-
# It can also optionally implement the #load_all() method, which returns
|
19
|
-
# a collection of objects given a collection of primary keys, if that can be
|
20
|
-
# done more efficiently than calling #load() on each key.
|
21
|
-
# Instance adapter::
|
22
|
-
# A subclass of Sunspot::Adapters::InstanceAdapter, this object is
|
23
|
-
# instantiated with a particular instance. Its only job is to tell Sunspot
|
24
|
-
# what the object's primary key is, by implementing the #id() method.
|
25
|
-
#
|
26
|
-
# Adapters are registered by registering their two components, telling Sunspot
|
27
|
-
# that they are available for one or more classes, and all of their
|
28
|
-
# subclasses. See Sunspot::Adapters::DataAccessor.register and
|
29
|
-
# Sunspot::Adapters::InstanceAdapter.register for the details.
|
30
|
-
#
|
31
|
-
# See spec/mocks/mock_adapter.rb for an example of how adapter classes should
|
32
|
-
# be implemented.
|
33
|
-
#
|
34
|
-
module Adapters
|
35
|
-
# Subclasses of the InstanceAdapter class should implement the #id method,
|
36
|
-
# which returns the primary key of the instance stored in the @instance
|
37
|
-
# variable. The primary key must be unique within the scope of the
|
38
|
-
# instance's class.
|
39
|
-
#
|
40
|
-
# ==== Example:
|
41
|
-
#
|
42
|
-
# class FileAdapter < Sunspot::Adapters::InstanceAdapter
|
43
|
-
# def id
|
44
|
-
# File.expand_path(@instance.path)
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# # then in your initializer
|
49
|
-
# Sunspot::Adapters::InstanceAdapter.register(MyAdapter, File)
|
50
|
-
#
|
51
|
-
class InstanceAdapter
|
52
|
-
def initialize(instance) #:nodoc:
|
53
|
-
@instance = instance
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# The universally-unique ID for this instance that will be stored in solr
|
58
|
-
#
|
59
|
-
# ==== Returns
|
60
|
-
#
|
61
|
-
# String:: ID for use in Solr
|
62
|
-
#
|
63
|
-
def index_id #:nodoc:
|
64
|
-
InstanceAdapter.index_id_for(@instance.class.name, id)
|
65
|
-
end
|
66
|
-
|
67
|
-
class <<self
|
68
|
-
# Instantiate an InstanceAdapter for the given object, searching for
|
69
|
-
# registered adapters for the object's class.
|
70
|
-
#
|
71
|
-
# ==== Parameters
|
72
|
-
#
|
73
|
-
# instance<Object>:: The instance to adapt
|
74
|
-
#
|
75
|
-
# ==== Returns
|
76
|
-
#
|
77
|
-
# InstanceAdapter::
|
78
|
-
# An instance of an InstanceAdapter implementation that
|
79
|
-
# wraps the given instance
|
80
|
-
#
|
81
|
-
def adapt(instance) #:nodoc:
|
82
|
-
@known_adapters ||= {}
|
83
|
-
clazz = instance.class
|
84
|
-
adapter = @known_adapters[clazz.name.to_sym] || self.for(clazz)
|
85
|
-
@known_adapters[clazz.name.to_sym] ||= adapter
|
86
|
-
adapter.new(instance)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Register an instance adapter for a set of classes. When searching for
|
90
|
-
# an adapter for a given instance, Sunspot starts with the instance's
|
91
|
-
# class, and then searches for registered adapters up the class's
|
92
|
-
# ancestor chain.
|
93
|
-
#
|
94
|
-
# ==== Parameters
|
95
|
-
#
|
96
|
-
# instance_adapter<Class>:: The instance adapter class to register
|
97
|
-
# classes...<Class>::
|
98
|
-
# One or more classes that this instance adapter adapts
|
99
|
-
#
|
100
|
-
def register(instance_adapter, *classes)
|
101
|
-
classes.each do |clazz|
|
102
|
-
instance_adapters[clazz.name.to_sym] = instance_adapter
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Find the best InstanceAdapter implementation that adapts the given
|
107
|
-
# class. Starting with the class and then moving up the ancestor chain,
|
108
|
-
# looks for registered InstanceAdapter implementations.
|
109
|
-
#
|
110
|
-
# ==== Parameters
|
111
|
-
#
|
112
|
-
# clazz<Class>:: The class to find an InstanceAdapter for
|
113
|
-
#
|
114
|
-
# ==== Returns
|
115
|
-
#
|
116
|
-
# Class:: Subclass of InstanceAdapter, or nil if none found
|
117
|
-
#
|
118
|
-
# ==== Raises
|
119
|
-
#
|
120
|
-
# Sunspot::NoAdapterError:: If no adapter is registered for this class
|
121
|
-
#
|
122
|
-
def for(clazz) #:nodoc:
|
123
|
-
original_class_name = clazz.name
|
124
|
-
clazz.ancestors.each do |ancestor_class|
|
125
|
-
next if ancestor_class.name.nil? || ancestor_class.name.empty?
|
126
|
-
class_name = ancestor_class.name.to_sym
|
127
|
-
return instance_adapters[class_name] if instance_adapters[class_name]
|
128
|
-
end
|
129
|
-
|
130
|
-
raise(Sunspot::NoAdapterError,
|
131
|
-
"No adapter is configured for #{original_class_name} or its superclasses. See the documentation for Sunspot::Adapters")
|
132
|
-
end
|
133
|
-
|
134
|
-
def index_id_for(class_name, id) #:nodoc:
|
135
|
-
"#{class_name} #{id}"
|
136
|
-
end
|
137
|
-
|
138
|
-
protected
|
139
|
-
|
140
|
-
# Lazy-initialize the hash of registered instance adapters
|
141
|
-
#
|
142
|
-
# ==== Returns
|
143
|
-
#
|
144
|
-
# Hash:: Hash containing class names keyed to instance adapter classes
|
145
|
-
#
|
146
|
-
def instance_adapters #:nodoc:
|
147
|
-
@instance_adapters ||= {}
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# Subclasses of the DataAccessor class take care of retrieving instances of
|
153
|
-
# the adapted class from (usually persistent) storage. Subclasses must
|
154
|
-
# implement the #load method, which takes an id (the value returned by
|
155
|
-
# InstanceAdapter#id, as a string), and returns the instance referenced by
|
156
|
-
# that ID. Optionally, it can also override the #load_all method, which
|
157
|
-
# takes an array of IDs and returns an array of instances in the order
|
158
|
-
# given. #load_all need only be implemented if it can be done more
|
159
|
-
# efficiently than simply iterating over the IDs and calling #load on each
|
160
|
-
# individually.
|
161
|
-
#
|
162
|
-
# ==== Example
|
163
|
-
#
|
164
|
-
# class FileAccessor < Sunspot::Adapters::InstanceAdapter
|
165
|
-
# def load(id)
|
166
|
-
# @clazz.open(id)
|
167
|
-
# end
|
168
|
-
# end
|
169
|
-
#
|
170
|
-
# Sunspot::Adapters::DataAccessor.register(FileAccessor, File)
|
171
|
-
#
|
172
|
-
class DataAccessor
|
173
|
-
# Attributes that should be passed to other adapted subclasses
|
174
|
-
attr_accessor :inherited_attributes
|
175
|
-
attr_reader :clazz
|
176
|
-
|
177
|
-
def initialize(clazz) #:nodoc:
|
178
|
-
@clazz = clazz
|
179
|
-
@inherited_attributes = []
|
180
|
-
end
|
181
|
-
|
182
|
-
# Subclasses can override this class to provide more efficient bulk
|
183
|
-
# loading of instances. Instances must be returned in the same order
|
184
|
-
# that the IDs were given.
|
185
|
-
#
|
186
|
-
# ==== Parameters
|
187
|
-
#
|
188
|
-
# ids<Array>:: collection of IDs
|
189
|
-
#
|
190
|
-
# ==== Returns
|
191
|
-
#
|
192
|
-
# Array:: collection of instances, in order of IDs given
|
193
|
-
#
|
194
|
-
def load_all(ids)
|
195
|
-
ids.map { |id| self.load(id) }
|
196
|
-
end
|
197
|
-
|
198
|
-
class <<self
|
199
|
-
# Create a DataAccessor for the given class, searching registered
|
200
|
-
# adapters for the best match. See InstanceAdapter#adapt for discussion
|
201
|
-
# of inheritance.
|
202
|
-
#
|
203
|
-
# ==== Parameters
|
204
|
-
#
|
205
|
-
# clazz<Class>:: Class to create DataAccessor for
|
206
|
-
#
|
207
|
-
# ==== Returns
|
208
|
-
#
|
209
|
-
# DataAccessor::
|
210
|
-
# DataAccessor implementation which provides access to given class
|
211
|
-
#
|
212
|
-
def create(clazz) #:nodoc:
|
213
|
-
self.for(clazz).new(clazz)
|
214
|
-
end
|
215
|
-
|
216
|
-
# Register data accessor for a set of classes. When searching for
|
217
|
-
# an accessor for a given class, Sunspot starts with the class,
|
218
|
-
# and then searches for registered adapters up the class's ancestor
|
219
|
-
# chain.
|
220
|
-
#
|
221
|
-
# ==== Parameters
|
222
|
-
#
|
223
|
-
# data_accessor<Class>:: The data accessor class to register
|
224
|
-
# classes...<Class>::
|
225
|
-
# One or more classes that this data accessor provides access to
|
226
|
-
#
|
227
|
-
def register(data_accessor, *classes)
|
228
|
-
classes.each do |clazz|
|
229
|
-
data_accessors[clazz.name.to_sym] = data_accessor
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
# Find the best DataAccessor implementation that adapts the given class.
|
234
|
-
# Starting with the class and then moving up the ancestor chain, looks
|
235
|
-
# for registered DataAccessor implementations.
|
236
|
-
#
|
237
|
-
# ==== Parameters
|
238
|
-
#
|
239
|
-
# clazz<Class>:: The class to find a DataAccessor for
|
240
|
-
#
|
241
|
-
# ==== Returns
|
242
|
-
#
|
243
|
-
# Class:: Implementation of DataAccessor
|
244
|
-
#
|
245
|
-
# ==== Raises
|
246
|
-
#
|
247
|
-
# Sunspot::NoAdapterError:: If no data accessor exists for the given class
|
248
|
-
#
|
249
|
-
def for(clazz) #:nodoc:
|
250
|
-
original_class_name = clazz.name
|
251
|
-
clazz.ancestors.each do |ancestor_class|
|
252
|
-
next if ancestor_class.name.nil? || ancestor_class.name.empty?
|
253
|
-
class_name = ancestor_class.name.to_sym
|
254
|
-
return data_accessors[class_name] if data_accessors[class_name]
|
255
|
-
end
|
256
|
-
raise(Sunspot::NoAdapterError,
|
257
|
-
"No data accessor is configured for #{original_class_name} or its superclasses. See the documentation for Sunspot::Adapters")
|
258
|
-
end
|
259
|
-
|
260
|
-
protected
|
261
|
-
|
262
|
-
# Lazy-initialize the hash of registered data accessors
|
263
|
-
#
|
264
|
-
# ==== Returns
|
265
|
-
#
|
266
|
-
# Hash:: Hash containing class names keyed to data accessor classes
|
267
|
-
#
|
268
|
-
def data_accessors #:nodoc:
|
269
|
-
@adapters ||= {}
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
# Allows to have a registry of the classes adapted by a DataAccessor. This
|
275
|
-
# registry does the class registration using DataAccessor's #create and while
|
276
|
-
# doing so also allows a registered class to notify which attributes
|
277
|
-
# should be inherited by its subclasses.
|
278
|
-
# This is useful in cases such us ActiveRecord's #include option, where
|
279
|
-
# you may need to run a search in all the subclasses of a searchable model
|
280
|
-
# and including some associations for all of them when it loads.
|
281
|
-
#
|
282
|
-
# ==== Example
|
283
|
-
#
|
284
|
-
# # ActiveRecordDataAccessor marks :include and :select as inherited_attributes
|
285
|
-
# class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
|
286
|
-
# # options for the find
|
287
|
-
# attr_accessor :include, :select
|
288
|
-
#
|
289
|
-
# def initialize(clazz)
|
290
|
-
# super(clazz)
|
291
|
-
# @inherited_attributes = [:include, :select]
|
292
|
-
# end
|
293
|
-
# end
|
294
|
-
#
|
295
|
-
# class Event < ActiveRecord::Base
|
296
|
-
# searchable do
|
297
|
-
# #stuff here
|
298
|
-
# end
|
299
|
-
# end
|
300
|
-
# class Play < Event ; end
|
301
|
-
# class Movie < Event ; end
|
302
|
-
#
|
303
|
-
# # This will push the :include to ALL of the Event's subclasses
|
304
|
-
# @search = Event.search(include: [:images])
|
305
|
-
#
|
306
|
-
# # You can also set the value just one class's attribute
|
307
|
-
# @search.data_accessor_for(Play).include = [ :images, :location]
|
308
|
-
#
|
309
|
-
class Registry
|
310
|
-
extend Forwardable
|
311
|
-
|
312
|
-
def initialize
|
313
|
-
@reg = {}
|
314
|
-
end
|
315
|
-
def_delegator :@reg, :keys, :registered
|
316
|
-
def_delegators :@reg, :include?
|
317
|
-
|
318
|
-
def retrieve(clazz)
|
319
|
-
key = clazz.name.to_sym
|
320
|
-
if !@reg.include?(key)
|
321
|
-
data_accessor = inject_inherited_attributes_for( Adapters::DataAccessor.create(clazz) )
|
322
|
-
@reg[key] ||= data_accessor
|
323
|
-
end
|
324
|
-
@reg[key]
|
325
|
-
end
|
326
|
-
|
327
|
-
# It will inject declared attributes to be inherited from ancestors
|
328
|
-
# only if they are not already present in the data_accessor for each class.
|
329
|
-
def inject_inherited_attributes_for(data_accessor)
|
330
|
-
return data_accessor if @reg.empty?
|
331
|
-
|
332
|
-
data_accessor.inherited_attributes.each do |attribute|
|
333
|
-
if data_accessor.send(attribute).nil? # Inject only if the current class didn't define one.
|
334
|
-
inherited_value = nil
|
335
|
-
# Now try to find a value for the attribute in the chain of ancestors
|
336
|
-
data_accessor.clazz.ancestors.each do |ancestor|
|
337
|
-
next if ancestor.name.nil? || ancestor.name.empty?
|
338
|
-
key = ancestor.name.to_sym
|
339
|
-
inherited_value = @reg[key].send(attribute) if @reg[key]
|
340
|
-
break unless inherited_value.nil?
|
341
|
-
end
|
342
|
-
data_accessor.send("#{attribute.to_s}=", inherited_value) unless inherited_value.nil?
|
343
|
-
end
|
344
|
-
end
|
345
|
-
data_accessor
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# Keeps a stack of batches and helps out when Indexer is asked to batch documents.
|
4
|
-
#
|
5
|
-
# If the client does something like
|
6
|
-
#
|
7
|
-
# Sunspot.batch do
|
8
|
-
# some_code_here
|
9
|
-
# which_triggers_some_other_code
|
10
|
-
# which_again_calls
|
11
|
-
# Sunspot.batch { ... }
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# it is the Batcher's job to keep track of these nestings. The inner will
|
15
|
-
# be sent of to be indexed first.
|
16
|
-
#
|
17
|
-
class Batcher
|
18
|
-
include Enumerable
|
19
|
-
|
20
|
-
# Raised if you ask to end current, but no current exists
|
21
|
-
class NoCurrentBatchError < StandardError; end
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
@stack = []
|
25
|
-
end
|
26
|
-
|
27
|
-
def current
|
28
|
-
@stack.last or start_new
|
29
|
-
end
|
30
|
-
|
31
|
-
def start_new
|
32
|
-
(@stack << []).last
|
33
|
-
end
|
34
|
-
|
35
|
-
def end_current
|
36
|
-
fail NoCurrentBatchError if @stack.empty?
|
37
|
-
|
38
|
-
@stack.pop
|
39
|
-
end
|
40
|
-
|
41
|
-
def depth
|
42
|
-
@stack.length
|
43
|
-
end
|
44
|
-
|
45
|
-
def batching?
|
46
|
-
depth > 0
|
47
|
-
end
|
48
|
-
|
49
|
-
def each(&block)
|
50
|
-
current.each(&block)
|
51
|
-
end
|
52
|
-
|
53
|
-
def push(value)
|
54
|
-
current << value
|
55
|
-
end
|
56
|
-
alias << push
|
57
|
-
|
58
|
-
def concat(values)
|
59
|
-
current.concat values
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
class ClassSet
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@name_to_klass = {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def <<(klass)
|
10
|
-
@name_to_klass[klass.name.to_sym] = klass
|
11
|
-
self
|
12
|
-
end
|
13
|
-
alias_method :add, :<<
|
14
|
-
|
15
|
-
def each(&block)
|
16
|
-
@name_to_klass.values.each(&block)
|
17
|
-
end
|
18
|
-
|
19
|
-
def empty?
|
20
|
-
@name_to_klass.empty?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,202 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
#
|
3
|
-
# The CompositeSetup class encapsulates a collection of setups, and responds
|
4
|
-
# to a subset of the methods that Setup responds to (in particular, the
|
5
|
-
# methods required to build queries).
|
6
|
-
#
|
7
|
-
class CompositeSetup #:nodoc:
|
8
|
-
class << self
|
9
|
-
alias_method :for, :new
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(types)
|
13
|
-
@types = types
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# Collection of Setup objects for the enclosed types
|
18
|
-
#
|
19
|
-
# ==== Returns
|
20
|
-
#
|
21
|
-
# Array:: Collection of Setup objects
|
22
|
-
#
|
23
|
-
def setups
|
24
|
-
@setups ||= @types.map { |type| Setup.for(type) }
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Return the names of the encapsulated types
|
29
|
-
#
|
30
|
-
# ==== Returns
|
31
|
-
#
|
32
|
-
# Array:: Collection of class names
|
33
|
-
#
|
34
|
-
def type_names
|
35
|
-
@type_names ||= @types.map { |clazz| clazz.name }
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
# Get a text field object by its public name. A field will be returned if
|
40
|
-
# it is configured for any of the enclosed types.
|
41
|
-
#
|
42
|
-
# ==== Returns
|
43
|
-
#
|
44
|
-
# Sunspot::FulltextField:: Text field with the given public name
|
45
|
-
#
|
46
|
-
# ==== Raises
|
47
|
-
#
|
48
|
-
# UnrecognizedFieldError::
|
49
|
-
# If no field with that name is configured for any of the enclosed types.
|
50
|
-
#
|
51
|
-
def text_fields(field_name)
|
52
|
-
if text_fields = text_fields_hash[field_name.to_sym]
|
53
|
-
text_fields.to_a
|
54
|
-
else
|
55
|
-
raise(
|
56
|
-
UnrecognizedFieldError,
|
57
|
-
"No text field configured for #{@types * ', '} with name '#{field_name}'"
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Get a Sunspot::AttributeField instance corresponding to the given field name
|
64
|
-
#
|
65
|
-
# ==== Parameters
|
66
|
-
#
|
67
|
-
# field_name<Symbol>:: The public field name for which to find a field
|
68
|
-
#
|
69
|
-
# ==== Returns
|
70
|
-
#
|
71
|
-
# Sunspot::AttributeField The field object corresponding to the given name
|
72
|
-
#
|
73
|
-
# ==== Raises
|
74
|
-
#
|
75
|
-
# ArgumentError::
|
76
|
-
# If the given field name is not configured for the types being queried
|
77
|
-
#
|
78
|
-
def field(field_name) #:nodoc:
|
79
|
-
fields_hash[field_name.to_sym] || raise(
|
80
|
-
UnrecognizedFieldError,
|
81
|
-
"No field configured for #{@types * ', '} with name '#{field_name}'"
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Get a dynamic field factory for the given base name.
|
87
|
-
#
|
88
|
-
# ==== Returns
|
89
|
-
#
|
90
|
-
# DynamicFieldFactory:: Factory for dynamic fields with the given base name
|
91
|
-
#
|
92
|
-
# ==== Raises
|
93
|
-
#
|
94
|
-
# UnrecognizedFieldError::
|
95
|
-
# If the given base name is not configured as a dynamic field for the types being queried
|
96
|
-
#
|
97
|
-
def dynamic_field_factory(field_name)
|
98
|
-
dynamic_field_factories_hash[field_name.to_sym] || raise(
|
99
|
-
UnrecognizedFieldError,
|
100
|
-
"No dynamic field configured for #{@types * ', '} with name #{field_name.inspect}"
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
#
|
105
|
-
# Collection of all text fields configured for any of the enclosed types.
|
106
|
-
#
|
107
|
-
# === Returns
|
108
|
-
#
|
109
|
-
# Array:: Text fields configured for the enclosed types
|
110
|
-
#
|
111
|
-
def all_text_fields
|
112
|
-
@text_fields ||= text_fields_hash.values.map { |set| set.to_a }.flatten
|
113
|
-
end
|
114
|
-
|
115
|
-
def all_more_like_this_fields
|
116
|
-
@more_like_this_fields ||= more_like_this_fields_hash.values.map { |set| set.to_a }.flatten
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
#
|
122
|
-
# Return a hash of field names to text field objects, containing all fields
|
123
|
-
# that are configured for any of the types enclosed.
|
124
|
-
#
|
125
|
-
# ==== Returns
|
126
|
-
#
|
127
|
-
# Hash:: Hash of field names to text field objects.
|
128
|
-
#
|
129
|
-
def text_fields_hash
|
130
|
-
@text_fields_hash ||=
|
131
|
-
setups.inject({}) do |hash, setup|
|
132
|
-
setup.all_text_fields.each do |text_field|
|
133
|
-
(hash[text_field.name] ||= Set.new) << text_field
|
134
|
-
end
|
135
|
-
hash
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def more_like_this_fields_hash
|
140
|
-
@more_like_this_fields_hash ||=
|
141
|
-
setups.inject({}) do |hash, setup|
|
142
|
-
setup.all_more_like_this_fields.each do |more_like_this_field|
|
143
|
-
(hash[more_like_this_field.name] ||= Set.new) << more_like_this_field
|
144
|
-
end
|
145
|
-
hash
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
#
|
150
|
-
# Return a hash of field names to field objects, containing all fields
|
151
|
-
# that are common to all of the classes enclosed. In order for fields
|
152
|
-
# to be common, they must be of the same type and have the same
|
153
|
-
# value for allow_multiple? and stored?. This method is memoized.
|
154
|
-
#
|
155
|
-
# ==== Returns
|
156
|
-
#
|
157
|
-
# Hash:: field names keyed to field objects
|
158
|
-
#
|
159
|
-
def fields_hash
|
160
|
-
@fields_hash ||=
|
161
|
-
begin
|
162
|
-
field_sets_hash = Hash.new { |h, k| h[k] = Set.new }
|
163
|
-
@types.each do |type|
|
164
|
-
Setup.for(type).fields.each do |field|
|
165
|
-
field_sets_hash[field.name.to_sym] << field
|
166
|
-
end
|
167
|
-
end
|
168
|
-
fields_hash = {}
|
169
|
-
field_sets_hash.each_pair do |field_name, set|
|
170
|
-
if set.length == 1
|
171
|
-
fields_hash[field_name] = set.to_a.first
|
172
|
-
end
|
173
|
-
end
|
174
|
-
fields_hash
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
#
|
179
|
-
# Return a hash of dynamic field base names to dynamic field factories for
|
180
|
-
# those base names. Criteria for the inclusion are the same as for
|
181
|
-
# #fields_hash()
|
182
|
-
#
|
183
|
-
def dynamic_field_factories_hash
|
184
|
-
@dynamic_field_factories_hash ||=
|
185
|
-
begin
|
186
|
-
dynamic_field_factories_hash = @types.inject({}) do |hash, type|
|
187
|
-
Setup.for(type).dynamic_field_factories.each do |field_factory|
|
188
|
-
(hash[field_factory.name.to_sym] ||= {})[type.name] = field_factory
|
189
|
-
end
|
190
|
-
hash
|
191
|
-
end
|
192
|
-
dynamic_field_factories_hash.each_pair do |field_name, field_configurations_hash|
|
193
|
-
if @types.any? { |type| field_configurations_hash[type.name].nil? }
|
194
|
-
dynamic_field_factories_hash.delete(field_name)
|
195
|
-
else
|
196
|
-
dynamic_field_factories_hash[field_name] = field_configurations_hash.values.first
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|