flex 0.4.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/README.md +46 -7
- data/VERSION +1 -1
- data/flex.gemspec +13 -19
- data/lib/flex.rb +66 -392
- data/lib/flex/api_stubs.rb +1268 -0
- data/lib/flex/api_templates/cluster_api.yml +94 -0
- data/lib/flex/api_templates/core_api.yml +202 -0
- data/lib/flex/api_templates/indices_api.yml +304 -0
- data/lib/flex/class_proxy/base.rb +20 -6
- data/lib/flex/class_proxy/templates.rb +97 -0
- data/lib/flex/class_proxy/templates/doc.rb +91 -0
- data/lib/flex/class_proxy/templates/search.rb +72 -0
- data/lib/flex/configuration.rb +17 -49
- data/lib/flex/deprecation.rb +153 -0
- data/lib/flex/errors.rb +2 -1
- data/lib/flex/http_clients/base.rb +15 -0
- data/lib/flex/http_clients/loader.rb +51 -0
- data/lib/flex/http_clients/patron.rb +9 -7
- data/lib/flex/http_clients/rest_client.rb +6 -8
- data/lib/flex/logger.rb +24 -3
- data/lib/flex/prog_bar.rb +11 -6
- data/lib/flex/rails.rb +1 -13
- data/lib/flex/result.rb +8 -2
- data/lib/flex/result/document.rb +42 -13
- data/lib/flex/result/multi_get.rb +24 -0
- data/lib/flex/result/search.rb +1 -24
- data/lib/flex/struct/array.rb +25 -0
- data/lib/flex/struct/hash.rb +105 -0
- data/lib/flex/{result/collection.rb → struct/paginable.rb} +16 -9
- data/lib/flex/struct/prunable.rb +60 -0
- data/lib/flex/struct/symbolize.rb +27 -0
- data/lib/flex/tasks.rb +26 -86
- data/lib/flex/template.rb +60 -120
- data/lib/flex/template/common.rb +42 -0
- data/lib/flex/template/logger.rb +66 -0
- data/lib/flex/template/partial.rb +12 -15
- data/lib/flex/template/search.rb +6 -6
- data/lib/flex/template/slim_search.rb +1 -1
- data/lib/flex/template/tags.rb +19 -9
- data/lib/flex/templates.rb +20 -0
- data/lib/flex/utility_methods.rb +80 -89
- data/lib/flex/utils.rb +68 -25
- data/lib/flex/variables.rb +55 -4
- data/lib/tasks.rake +28 -0
- metadata +61 -85
- data/bin/flexes +0 -174
- data/lib/flex/api_methods.yml +0 -108
- data/lib/flex/class_proxy/loader.rb +0 -102
- data/lib/flex/class_proxy/model.rb +0 -45
- data/lib/flex/class_proxy/model_sync.rb +0 -23
- data/lib/flex/class_proxy/related_model.rb +0 -23
- data/lib/flex/instance_proxy/base.rb +0 -29
- data/lib/flex/instance_proxy/model.rb +0 -102
- data/lib/flex/instance_proxy/related_model.rb +0 -7
- data/lib/flex/loader.rb +0 -18
- data/lib/flex/manager.rb +0 -61
- data/lib/flex/model.rb +0 -24
- data/lib/flex/rails/engine.rb +0 -23
- data/lib/flex/rails/helper.rb +0 -16
- data/lib/flex/related_model.rb +0 -16
- data/lib/flex/result/indifferent_access.rb +0 -11
- data/lib/flex/result/source_document.rb +0 -63
- data/lib/flex/result/source_search.rb +0 -32
- data/lib/flex/structure/indifferent_access.rb +0 -44
- data/lib/flex/structure/mergeable.rb +0 -21
- data/lib/flex/template/base.rb +0 -41
- data/lib/flex/template/info.rb +0 -68
- data/lib/generators/flex/setup/setup_generator.rb +0 -48
- data/lib/generators/flex/setup/templates/flex_config.yml +0 -16
- data/lib/generators/flex/setup/templates/flex_dir/es.rb.erb +0 -18
- data/lib/generators/flex/setup/templates/flex_dir/es.yml.erb +0 -19
- data/lib/generators/flex/setup/templates/flex_dir/es_extender.rb.erb +0 -17
- data/lib/generators/flex/setup/templates/flex_initializer.rb.erb +0 -44
- data/lib/tasks/index.rake +0 -17
- data/test/flex.irt +0 -143
- data/test/flex/configuration.irt +0 -53
- data/test/irt_helper.rb +0 -12
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'prompter'
|
2
|
-
|
3
|
-
class Flex::SetupGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
|
7
|
-
def self.banner
|
8
|
-
"rails generate flex:setup"
|
9
|
-
end
|
10
|
-
|
11
|
-
def ask_base_name
|
12
|
-
@class_name = Prompter.ask('Please, enter a class name for your Search class. Choose a name not defined in your app.',
|
13
|
-
:default => 'FlexSearch', :hint => '[<enter>=FlexSearch]')
|
14
|
-
@extender_name = "#{@class_name}Extender"
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_config_flex_file
|
18
|
-
template 'flex_config.yml', Rails.root.join('config', 'flex.yml')
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_initializer_file
|
22
|
-
template 'flex_initializer.rb.erb', Rails.root.join('config', 'initializers', 'flex.rb')
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_flex_dir
|
26
|
-
template 'flex_dir/es.rb.erb', Rails.root.join('app', 'flex', "#{@class_name.underscore}.rb")
|
27
|
-
template 'flex_dir/es.yml.erb', Rails.root.join('app', 'flex', "#{@class_name.underscore}.yml")
|
28
|
-
template 'flex_dir/es_extender.rb.erb', Rails.root.join('app', 'flex', "#{@extender_name.underscore}.rb")
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def show_setup_message
|
33
|
-
say <<-text, :style => :green
|
34
|
-
|
35
|
-
Setup done!
|
36
|
-
|
37
|
-
During prototyping, remember also:
|
38
|
-
|
39
|
-
1. each time you add a `Flex::Model` you should add its name to the "config/initializers/flex.rb"
|
40
|
-
2. each time you add/change a flex.parent relation you should reindex your DB(s) with rake `flex:import FORCE=true`
|
41
|
-
|
42
|
-
The complete documentation is available at https://github.com/ddnexus/flex/wiki
|
43
|
-
If you have any problem with Flex, please report the issue at https://github.com/ddnexus/flex/issues.
|
44
|
-
text
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# ANCHORS litheral key: it will not be used as template
|
2
|
-
# you can store here fragments of structures to reuse below
|
3
|
-
ANCHORS:
|
4
|
-
-
|
5
|
-
|
6
|
-
# This is a dynamic index name The settings and mapping below will work with any index.
|
7
|
-
# The default index name generated by Flex is usually <application_name>_<environment>,
|
8
|
-
# but you may have changed it in the initializers/flex.rb or you can hardcode it if you prefer.
|
9
|
-
<%%= Flex::Configuration.variables[:index] %>:
|
10
|
-
|
11
|
-
settings:
|
12
|
-
number_of_shards: 5
|
13
|
-
number_of_replicas: 1
|
14
|
-
|
15
|
-
# add your custom mappings here
|
16
|
-
mappings: {}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# inspect the methods loaded in this module and their usage
|
2
|
-
# in the rails console by just typing:
|
3
|
-
# >> puts <%= @class_name %>.flex.info
|
4
|
-
# you can eventually restrict the info to a single method by pasing its name:
|
5
|
-
# >> puts <%= @class_name %>.flex.info :search
|
6
|
-
# see the detailed doc for this feature at https://github.com/ddnexus/flex/wiki/Selfdoc
|
7
|
-
|
8
|
-
module <%= @class_name %>
|
9
|
-
|
10
|
-
extend self
|
11
|
-
|
12
|
-
include Flex::Loader
|
13
|
-
flex.load_search_source
|
14
|
-
|
15
|
-
# you may need to add more method here, usually wrapper methods
|
16
|
-
# that use one of the autogenerated methods from the loaded templates
|
17
|
-
|
18
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Add here your search queries
|
2
|
-
# see the detailed Source documentation at https://github.com/ddnexus/flex/wiki/Sources
|
3
|
-
|
4
|
-
|
5
|
-
# ANCHORS litheral key: it will not be used as template
|
6
|
-
# you can store here fragments of queries to reuse in the templates below
|
7
|
-
ANCHORS:
|
8
|
-
-
|
9
|
-
|
10
|
-
# this is a a basic template loaded in your class <%= @class_name %>
|
11
|
-
# it defines the 'q' tag. You can check its usage from the rails console by just typing:
|
12
|
-
# >> puts <%= @class_name %>.flex.info
|
13
|
-
# You can eventually restrict the info to a single method by pasing its name:
|
14
|
-
# >> puts <%= @class_name %>.flex.info :search
|
15
|
-
# see the detailed doc for this feature at https://github.com/ddnexus/flex/wiki/Selfdoc
|
16
|
-
search:
|
17
|
-
- query:
|
18
|
-
query_string: <<q= "*">>
|
19
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# see the detailed Extenders documentation at https://github.com/ddnexus/flex/wiki/Extenders
|
2
|
-
|
3
|
-
module <%= @extender_name %>
|
4
|
-
|
5
|
-
# set this method to restrict this extender to certain types of results
|
6
|
-
# see the other Flex extenders for reference (https://github.com/ddnexus/flex/tree/master/lib/flex/result)
|
7
|
-
def self.should_extend?(response)
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
# adds your methods
|
12
|
-
|
13
|
-
def an_extending_method
|
14
|
-
# self is the structure returned by ES
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# see the detailed Configuration documentation at https://github.com/ddnexus/flex/wiki/Configuration
|
2
|
-
|
3
|
-
Flex::Configuration.configure do |config|
|
4
|
-
|
5
|
-
# you MUST add your indexed model names here
|
6
|
-
config.flex_models = %w[ ]
|
7
|
-
|
8
|
-
# Add the your result extenders here
|
9
|
-
config.result_extenders |= [ <%= "#{@extender_name}" %> ]
|
10
|
-
|
11
|
-
# Add the default variables here
|
12
|
-
# see also the details Variables documentation at https://github.com/ddnexus/flex/wiki/Variables
|
13
|
-
# config.variables.add :index => 'my_index',
|
14
|
-
# :type => 'project',
|
15
|
-
# :anything => 'anything
|
16
|
-
|
17
|
-
# The custom url of your ElasticSearch server
|
18
|
-
# config.base_uri = 'http://localhost:9200'
|
19
|
-
|
20
|
-
# Set it to true to log the debug infos (true by default in development mode)
|
21
|
-
# config.debug = false
|
22
|
-
|
23
|
-
# Debug info are actually valid curl commands
|
24
|
-
# config.debug_to_curl = false
|
25
|
-
|
26
|
-
# The custom logger you want Flex to use. Default Rails.logger
|
27
|
-
# config.logger = Logger.new(STDERR)
|
28
|
-
|
29
|
-
# Custom config file path
|
30
|
-
# config.config_file = '/custom/path/to/flex.yml',
|
31
|
-
|
32
|
-
# Custom flex dir path
|
33
|
-
# config.flex_dir = '/custom/path/to/flex',
|
34
|
-
|
35
|
-
# The custom http_client you may want to implement
|
36
|
-
# config.http_client = 'Your::Client'
|
37
|
-
|
38
|
-
# The options passed to the http_client. They are client specific.
|
39
|
-
# config.http_client_options = {:timeout => 5}
|
40
|
-
|
41
|
-
# Experimental: checks the response and return a boolean (should raise?)
|
42
|
-
# config.raise_proc = proc{|response| response.status >= 400}
|
43
|
-
|
44
|
-
end
|
data/lib/tasks/index.rake
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require defined?(Rails) ? 'flex/rails' : 'flex'
|
2
|
-
require 'flex/tasks'
|
3
|
-
|
4
|
-
env = defined?(Rails) ? :environment : []
|
5
|
-
|
6
|
-
namespace :flex do
|
7
|
-
|
8
|
-
desc 'imports from an ActiveRecord or Mongoid models'
|
9
|
-
task(:import => env) { Flex::Tasks.import_models }
|
10
|
-
|
11
|
-
desc 'creates indices from the Flex::Configuration.config_file file'
|
12
|
-
task(:create_indices => env) { Flex::Tasks.create_indices }
|
13
|
-
|
14
|
-
desc 'destroys indices in the Flex::Configuration.config_file file'
|
15
|
-
task(:delete_indices => env) { Flex::Tasks.delete_indices }
|
16
|
-
|
17
|
-
end
|
data/test/flex.irt
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
desc 'check version'
|
2
|
-
Flex::VERSION
|
3
|
-
_eql?( "0.1" )
|
4
|
-
|
5
|
-
desc 'Flex responds to all public methods'
|
6
|
-
methods = [ # api methods from yaml
|
7
|
-
:indices_exists, :create_index, :put_index, :post_index, :get_settings, :put_mapping, :get_mapping, :delete_mapping,
|
8
|
-
:delete_index, :delete_by_query, :bulk, :count, :stats, :store, :put_store, :post_store, :remove, :get, :multi_get,
|
9
|
-
# utility_methods
|
10
|
-
:search, :slim_search, :HEAD, :GET, :PUT, :POST, :DELETE, :json2yaml, :yaml2json,
|
11
|
-
:process_bulk, :import_collection, :delete_collection,
|
12
|
-
# other methods
|
13
|
-
:exist? ]
|
14
|
-
defined, not_defined = methods.partition {|k| Flex.respond_to?(k)}
|
15
|
-
defined
|
16
|
-
_eql?( methods )
|
17
|
-
|
18
|
-
|
19
|
-
desc 'create index with PUT (explicit index)'
|
20
|
-
Flex.delete_index(:index => INDEX_NAME) if Flex.exist?(:index => INDEX_NAME)
|
21
|
-
Flex.put_index(:index => INDEX_NAME)
|
22
|
-
_eql?( {"ok"=>true, "acknowledged"=>true} )
|
23
|
-
|
24
|
-
|
25
|
-
# in the irt_helper.rb we set the default index to INDEX_NAME and Flex.reload! so we don't need to pass any explicit index
|
26
|
-
|
27
|
-
desc 'create index with PUT'
|
28
|
-
Flex.delete_index if Flex.exist?
|
29
|
-
Flex.put_index
|
30
|
-
_eql?( {"ok"=>true, "acknowledged"=>true} )
|
31
|
-
|
32
|
-
|
33
|
-
desc "index #{INDEX_NAME} exist"
|
34
|
-
Flex.exist?
|
35
|
-
_eql?( true )
|
36
|
-
|
37
|
-
|
38
|
-
desc "index #{unexistent = 'flex_unexistent_index'} doesn't exist'"
|
39
|
-
Flex.exist?(:index => unexistent)
|
40
|
-
_eql?( false )
|
41
|
-
|
42
|
-
|
43
|
-
desc 'create_index with POST (explicit index)'
|
44
|
-
Flex.delete_index(:index => TMP_INDEX_NAME) if Flex.exist?(:index => TMP_INDEX_NAME)
|
45
|
-
Flex.post_index(:index => TMP_INDEX_NAME)
|
46
|
-
_eql?( {"ok"=>true, "acknowledged"=>true} )
|
47
|
-
Flex.delete_index(:index => TMP_INDEX_NAME)
|
48
|
-
|
49
|
-
|
50
|
-
desc 'get_settings'
|
51
|
-
Flex.get_settings
|
52
|
-
_eql?( {"flex_test_index"=>{"settings"=>{"index.number_of_replicas"=>"1", "index.number_of_shards"=>"5", "index.version.created"=>"190299"}}} )
|
53
|
-
|
54
|
-
|
55
|
-
desc 'put_mapping'
|
56
|
-
Flex.put_mapping(:type => 'type1',
|
57
|
-
:properties => {'test1' => {'type' => 'string'} })
|
58
|
-
_eql?( {"ok"=>true, "acknowledged"=>true} )
|
59
|
-
|
60
|
-
|
61
|
-
desc 'check mapping'
|
62
|
-
Flex.get_mapping
|
63
|
-
_eql?( {"flex_test_index"=>{"type1"=>{"properties"=>{"test1"=>{"type"=>"string"}}}}} )
|
64
|
-
|
65
|
-
|
66
|
-
desc 'delete_mapping'
|
67
|
-
Flex.delete_mapping(:type => 'type1')
|
68
|
-
_eql?( {"ok"=>true} )
|
69
|
-
|
70
|
-
|
71
|
-
desc 'delete_index'
|
72
|
-
Flex.delete_index
|
73
|
-
_eql?( {"ok"=>true, "acknowledged"=>true} )
|
74
|
-
|
75
|
-
|
76
|
-
desc 'check delete_index'
|
77
|
-
Flex.exist?
|
78
|
-
_eql?( false )
|
79
|
-
|
80
|
-
|
81
|
-
desc 'store'
|
82
|
-
Flex.store(:type => 'type1', :id => 1, :data => {'a'=>2, 'b'=>3})
|
83
|
-
_eql?( {"ok"=>true, "_index"=>"flex_test_index", "_type"=>"type1", "_id"=>"1", "_version"=>1} )
|
84
|
-
|
85
|
-
|
86
|
-
desc 'get'
|
87
|
-
Flex.get(:type => 'type1', :id => 1)
|
88
|
-
_eql?( {"_index"=>"flex_test_index", "_type"=>"type1", "_id"=>"1", "_version"=>1, "exists"=>true, "_source"=>{"a"=>2, "b"=>3}} )
|
89
|
-
|
90
|
-
|
91
|
-
desc 'count (may fail in test, but it\'s ok)'
|
92
|
-
Flex.count :type => 'type1'
|
93
|
-
_eql?( {"count"=>1, "_shards"=>{"total"=>5, "successful"=>5, "failed"=>0}} )
|
94
|
-
|
95
|
-
|
96
|
-
desc 'remove'
|
97
|
-
Flex.remove(:type => 'type1', :id => 1)
|
98
|
-
_eql?( {"ok"=>true, "found"=>true, "_index"=>"flex_test_index", "_type"=>"type1", "_id"=>"1", "_version"=>2} )
|
99
|
-
|
100
|
-
|
101
|
-
desc 'check remove'
|
102
|
-
Flex.get(:type => 'type1', :id => 1, :raise => false)
|
103
|
-
_eql?( nil )
|
104
|
-
|
105
|
-
|
106
|
-
desc 'delete_by_query'
|
107
|
-
# in Patron the :data option is not working, since currently patron cannot send data with a DELETE request
|
108
|
-
Flex.store(:type => 'type1', :id => 1, :data => {'a'=>2, 'myfield'=>'pippo'})
|
109
|
-
Flex.delete_by_query :type => 'type1', :params => {:q => 'myfield:pippo'}
|
110
|
-
_eql?( {"ok"=>true, "_indices"=>{"flex_test_index"=>{"_shards"=>{"total"=>5, "successful"=>5, "failed"=>0}}}} )
|
111
|
-
|
112
|
-
|
113
|
-
desc 'strict_existence doesn\'t affect exist'
|
114
|
-
Flex.get(:type => 'type1', :id => 1, :raise => false)
|
115
|
-
_eql?( nil )
|
116
|
-
|
117
|
-
|
118
|
-
desc 'json2yaml'
|
119
|
-
struct = {:a => {:b => [3,4,5]}}
|
120
|
-
yaml = Flex.json2yaml MultiJson.encode(struct)
|
121
|
-
_eql? <<EOS
|
122
|
-
---
|
123
|
-
a:
|
124
|
-
b:
|
125
|
-
- 3
|
126
|
-
- 4
|
127
|
-
- 5
|
128
|
-
EOS
|
129
|
-
|
130
|
-
desc 'yaml2json'
|
131
|
-
Flex.yaml2json(yaml)
|
132
|
-
_eql?( "{\"a\":{\"b\":[3,4,5]}}" )
|
133
|
-
|
134
|
-
|
135
|
-
desc "exist with HEAD"
|
136
|
-
Flex.HEAD "/#{INDEX_NAME}"
|
137
|
-
# empty result object
|
138
|
-
_eql?( true )
|
139
|
-
|
140
|
-
desc "doesn't exist with HEAD'"
|
141
|
-
Flex.HEAD "/unexistent_flex_index"
|
142
|
-
_eql?( false )
|
143
|
-
|
data/test/flex/configuration.irt
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
|
2
|
-
desc 'Flex::Configuration responds to all public methods'
|
3
|
-
methods = [ # regular methods from class
|
4
|
-
:configure,
|
5
|
-
# data methods
|
6
|
-
:base_uri, :result_extenders, :logger, :variables, :flex_models, :config_file, :flex_dir,
|
7
|
-
:http_client, :http_client_options, :debug, :debug_to_curl, :raise_proc]
|
8
|
-
|
9
|
-
defined, not_defined = methods.partition {|k| Flex::Configuration.respond_to?(k)}
|
10
|
-
defined
|
11
|
-
_eql?( methods )
|
12
|
-
|
13
|
-
|
14
|
-
desc 'block set variables'
|
15
|
-
Flex::Configuration.configure do |conf|
|
16
|
-
conf.base_uri = 'http://something:123'
|
17
|
-
end
|
18
|
-
Flex::Configuration.base_uri
|
19
|
-
_eql?( "http://something:123" )
|
20
|
-
|
21
|
-
|
22
|
-
desc 'direct set variables'
|
23
|
-
Flex::Configuration.test = false
|
24
|
-
Flex::Configuration.test
|
25
|
-
_eql?( false )
|
26
|
-
|
27
|
-
|
28
|
-
desc 'new configuration object'
|
29
|
-
Flex::Configuration.configure do |conf|
|
30
|
-
conf.custom = 23
|
31
|
-
conf.base_uri = 'http://other_host:9200'
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
desc 'custom arg accessor'
|
36
|
-
Flex::Configuration.custom
|
37
|
-
_eql?( 23 )
|
38
|
-
|
39
|
-
|
40
|
-
desc 'modified configuration'
|
41
|
-
Flex::Configuration.base_uri
|
42
|
-
_eql?( 'http://other_host:9200' )
|
43
|
-
|
44
|
-
|
45
|
-
desc 'add custom configuration with accessor'
|
46
|
-
Flex::Configuration.new_custom = 3
|
47
|
-
_eql?( 3 )
|
48
|
-
|
49
|
-
|
50
|
-
desc 'custom option is in object'
|
51
|
-
Flex::Configuration.new_custom
|
52
|
-
_eql?( 3 )
|
53
|
-
|
data/test/irt_helper.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
require 'flex'
|
3
|
-
|
4
|
-
INDEX_NAME = 'flex_test_index'
|
5
|
-
TMP_INDEX_NAME = 'flex_tmp_test_index'
|
6
|
-
|
7
|
-
INDEX_NAME_1 = 'flex_test_index_1'
|
8
|
-
INDEX_NAME_2 = 'flex_test_index_2'
|
9
|
-
|
10
|
-
Flex.create_index(:index => INDEX_NAME) unless Flex.exist?(:index => INDEX_NAME)
|
11
|
-
Flex.config.variables[:index] = INDEX_NAME
|
12
|
-
Flex.reload!
|