cloudsearchable 0.0.1 → 0.0.2
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/cloudsearchable.gemspec
CHANGED
@@ -23,12 +23,16 @@ Gem::Specification.new do |spec|
|
|
23
23
|
"cloudsearchable.gemspec",
|
24
24
|
"lib/cloudsearchable.rb",
|
25
25
|
"lib/cloudsearchable/cloud_search.rb",
|
26
|
+
"lib/cloudsearchable/config.rb",
|
27
|
+
"lib/cloudsearchable/config/options.rb",
|
26
28
|
"lib/cloudsearchable/domain.rb",
|
27
29
|
"lib/cloudsearchable/field.rb",
|
28
30
|
"lib/cloudsearchable/query_chain.rb",
|
29
31
|
"lib/cloudsearchable/version.rb",
|
30
32
|
"spec/cloudsearchable/cloud_search_spec.rb",
|
31
33
|
"spec/cloudsearchable/cloudsearchable_spec.rb",
|
34
|
+
"spec/cloudsearchable/config/option_spec.rb",
|
35
|
+
"spec/cloudsearchable/config_spec.rb",
|
32
36
|
"spec/cloudsearchable/domain_spec.rb",
|
33
37
|
"spec/cloudsearchable/field_spec.rb",
|
34
38
|
"spec/cloudsearchable/query_chain_spec.rb",
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Cloudsearchable
|
2
|
+
module Config
|
3
|
+
|
4
|
+
# Encapsulates logic for setting options.
|
5
|
+
module Options
|
6
|
+
def self.included base
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
# Get the defaults or initialize a new empty hash.
|
12
|
+
def defaults
|
13
|
+
@defaults ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Reset the configuration options to the defaults.
|
17
|
+
def reset
|
18
|
+
settings.replace(defaults)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get the settings or initialize a new empty hash.
|
22
|
+
def settings
|
23
|
+
@settings ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Define a configuration option with a default. Example usage:
|
27
|
+
# Options.option(:persist_in_safe_mode, :default => false)
|
28
|
+
def option(name, options = {})
|
29
|
+
defaults[name] = settings[name] = options[:default]
|
30
|
+
|
31
|
+
define_method name do
|
32
|
+
settings[name]
|
33
|
+
end
|
34
|
+
|
35
|
+
define_method "#{name}=" do |value|
|
36
|
+
settings[name] = value
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method "#{name}?" do
|
40
|
+
!!settings[name]
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method "reset_#{name}" do
|
44
|
+
settings[name] = defaults[name]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "cloudsearchable/config/options"
|
2
|
+
|
3
|
+
module Cloudsearchable
|
4
|
+
|
5
|
+
# basic configuration for Cloudsearchable. Most of this code was patterned from Dynamoid.
|
6
|
+
module Config
|
7
|
+
extend self
|
8
|
+
include Options
|
9
|
+
|
10
|
+
option :domain_prefix, :default => defined?(Rails) ? "#{Rails.env}" : ""
|
11
|
+
option :fatal_warnings, :default => defined?(Rails) && Rails.env.production? ? false : true
|
12
|
+
option :logger, :default => defined?(Rails)
|
13
|
+
|
14
|
+
# The default logger either the Rails logger or just stdout.
|
15
|
+
def default_logger
|
16
|
+
defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the assigned logger instance.
|
20
|
+
def logger
|
21
|
+
@logger ||= default_logger
|
22
|
+
end
|
23
|
+
|
24
|
+
# If you want to, set the logger manually to any output you'd like. Or pass false or nil to disable logging entirely.
|
25
|
+
def logger=(logger)
|
26
|
+
case logger
|
27
|
+
when false, nil then @logger = nil
|
28
|
+
when true then @logger = default_logger
|
29
|
+
else
|
30
|
+
@logger = logger if logger.respond_to?(:info)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
#require 'cloudsearchable/config/options'
|
3
|
+
|
4
|
+
describe Cloudsearchable::Config::Options do
|
5
|
+
|
6
|
+
module ConfigTest
|
7
|
+
extend self
|
8
|
+
include Cloudsearchable::Config::Options
|
9
|
+
|
10
|
+
option :foo
|
11
|
+
option :timezone, :default => "PST"
|
12
|
+
option :warnings, :default => false
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { ConfigTest }
|
16
|
+
|
17
|
+
it 'sets and gets' do
|
18
|
+
subject.foo = 5
|
19
|
+
subject.foo.should eq 5
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'defaults' do
|
23
|
+
subject.warnings.should_not be_nil
|
24
|
+
subject.warnings.should eq subject.settings[:warnings]
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'resets option' do
|
28
|
+
subject.timezone = "EST"
|
29
|
+
subject.timezone.should eq "EST"
|
30
|
+
subject.reset_timezone
|
31
|
+
subject.timezone.should eq "PST"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'resets all options' do
|
35
|
+
subject.foo = 5
|
36
|
+
subject.reset
|
37
|
+
subject.foo.should eq nil
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cloudsearchable::Config do
|
4
|
+
it 'can be set in a block' do
|
5
|
+
Cloudsearchable.configure do |config|
|
6
|
+
config.domain_prefix = 'dev-llarue-'
|
7
|
+
end
|
8
|
+
|
9
|
+
Cloudsearchable.configure.domain_prefix.should eq 'dev-llarue-'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'aliases configure to config' do
|
13
|
+
Cloudsearchable.config.domain_prefix.should eq Cloudsearchable.configure.domain_prefix
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudsearchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -106,12 +106,16 @@ files:
|
|
106
106
|
- cloudsearchable.gemspec
|
107
107
|
- lib/cloudsearchable.rb
|
108
108
|
- lib/cloudsearchable/cloud_search.rb
|
109
|
+
- lib/cloudsearchable/config.rb
|
110
|
+
- lib/cloudsearchable/config/options.rb
|
109
111
|
- lib/cloudsearchable/domain.rb
|
110
112
|
- lib/cloudsearchable/field.rb
|
111
113
|
- lib/cloudsearchable/query_chain.rb
|
112
114
|
- lib/cloudsearchable/version.rb
|
113
115
|
- spec/cloudsearchable/cloud_search_spec.rb
|
114
116
|
- spec/cloudsearchable/cloudsearchable_spec.rb
|
117
|
+
- spec/cloudsearchable/config/option_spec.rb
|
118
|
+
- spec/cloudsearchable/config_spec.rb
|
115
119
|
- spec/cloudsearchable/domain_spec.rb
|
116
120
|
- spec/cloudsearchable/field_spec.rb
|
117
121
|
- spec/cloudsearchable/query_chain_spec.rb
|
@@ -145,6 +149,8 @@ summary: ActiveRecord-like query interface for AWS Cloud Search
|
|
145
149
|
test_files:
|
146
150
|
- spec/cloudsearchable/cloud_search_spec.rb
|
147
151
|
- spec/cloudsearchable/cloudsearchable_spec.rb
|
152
|
+
- spec/cloudsearchable/config/option_spec.rb
|
153
|
+
- spec/cloudsearchable/config_spec.rb
|
148
154
|
- spec/cloudsearchable/domain_spec.rb
|
149
155
|
- spec/cloudsearchable/field_spec.rb
|
150
156
|
- spec/cloudsearchable/query_chain_spec.rb
|