Module: Mebla

Extended by:
ActiveSupport::Autoload
Defined in:
lib/mebla.rb,
lib/mebla/errors.rb,
lib/mebla/search.rb,
lib/mebla/context.rb,
lib/mebla/railtie.rb,
lib/mebla/result_set.rb,
lib/mebla/configuration.rb,
lib/mebla/log_subscriber.rb,
lib/mebla/errors/mebla_error.rb,
lib/mebla/errors/mebla_fatal.rb,
lib/mebla/errors/mebla_index_exception.rb,
lib/generators/mebla/install/install_generator.rb,
lib/mebla/errors/mebla_configuration_exception.rb,
lib/mebla/errors/mebla_synchronization_exception.rb

Overview

A wrapper for slingshot elastic-search adapter for Mongoid

Defined Under Namespace

Modules: Errors Classes: Configuration, Context, InstallGenerator, LogSubscriber, Railtie, ResultSet, Search

Constant Summary collapse

@@mebla_mutex =
Mutex.new
@@context =
nil

Class Method Summary collapse

Class Method Details

.configure {|Mebla::Configuration.instance| ... } ⇒ Object

Configure Mebla

Example

Mebla.configure do |config|

index = "mebla_index"
host = "localhost"
port = 9200

end

Yields:



80
81
82
# File 'lib/mebla.rb', line 80

def self.configure(&block)
  yield Mebla::Configuration.instance
end

.contextnil

Returns Mebla’s context for minipulating the index

Returns:

  • (nil)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mebla.rb', line 30

def self.context
  if @@context.nil?
    @@mebla_mutex.synchronize do
      if @@context.nil?
        @@context = Mebla::Context.new          
      end
    end
  end
  
  @@context
end

.elasticsearch?Boolean

Check if elasticsearch is running

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/mebla.rb', line 64

def self.elasticsearch?
  result = Slingshot::Configuration.client.get "#{Slingshot::Configuration.url}/_status"
  return (result =~ /error/) ? false: true
rescue RestClient::Exception
  false
end

.log(message, level = :none) ⇒ nil

Note:

If no level is given a message of type Logger::UNKNOWN will be written to the log file

Writes out a message to the log file according to the level given

Parameters:

  • message (String)
  • level (Symbol) (defaults to: :none)

    can be :debug, :warn or :info

Returns:

  • (nil)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mebla.rb', line 90

def self.log(message, level = :none)    
  case level
  when :debug
    hook = "mebla_debug.mebla"
  when :warn
    hook = "mebla_warn.mebla"
  when :info
    hook = "mebla_info.mebla"
  else
    hook = "mebla_unknown.mebla"
  end
  
  ::ActiveSupport::Notifications.
    instrument(hook, :message => message)
end

.mongoid?Boolean

Check if mongoid is loaded

Returns:

  • (Boolean)


52
53
54
# File 'lib/mebla.rb', line 52

def self.mongoid?
  !defined?(Mongoid).nil?
end

.reset_context!nil

Resets the context (reloads Mebla)

Returns:

  • (nil)


44
45
46
47
48
# File 'lib/mebla.rb', line 44

def self.reset_context!
  @@mebla_mutex.synchronize do
    @@context = nil
  end
end

.search(query = "", type_names = nil) ⇒ Mebla::Search

Search the index

Search for all documents with a field ‘title’ with a value ‘Testing Search’

Mebla.search “title: Testing Search”

Parameters:

  • query (String) (defaults to: "")

    a string representing the search query

  • type_names (String, Symbol, Array) (defaults to: nil)

    a string, symbol or array representing the models to be searcheds

Returns:



114
115
116
# File 'lib/mebla.rb', line 114

def self.search(query = "", type_names = nil)
  Mebla::Search.new(query, type_names)
end

.slingshot?Boolean

Check if slingshot is loaded

Returns:

  • (Boolean)


58
59
60
# File 'lib/mebla.rb', line 58

def self.slingshot?
  !defined?(Slingshot).nil?
end