mark_mapper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8da86f713512ffdee54852951d9e1e2f94c0bf5
4
- data.tar.gz: 768ad651bee67d55396095b14db35963387fa9bc
3
+ metadata.gz: 8c87d8bd021a66b634a321779d977b24fa209d18
4
+ data.tar.gz: 50c1eef885256e24025205c026d6e4372e7748c4
5
5
  SHA512:
6
- metadata.gz: b78ac1946be9798b7b53f6299d2164cafd6b941b603584b1aa5ce720ce9139ffe85c5ca7ee00a30b41c00d292b4327b44f01e504ceb9f4c2b383e787446a1715
7
- data.tar.gz: 5dfb0ecac9c51de0b446d7466d56e7baedd97fe84f79102126aa21b6938fc194dc3c11fed2023a78749672abc3b473ee5a61750b20f30f037c929874948b084f
6
+ metadata.gz: df7c6c45d3016151096980251b5c8e49e3484745e55d1a23f0b9b276bdb5c4705262ff900b015b7ee71bbf9b725aa5515daef8c344b8a6a35050516185f7ed20
7
+ data.tar.gz: c7252b6b400fd3b7d345cc55d759564c88ad8b88b21d780a35ded5859583e00db31c7eefdee6dfb6bf570f0524e190cc87f46a6117c9fe0bc3e12bca78dd443c
@@ -56,5 +56,35 @@ module MarkMapper
56
56
  raise 'Set config before connecting. MarkMapper.config = {...}' unless defined?(@@config)
57
57
  @@config
58
58
  end
59
+
60
+ def setup(config, environment, options={})
61
+ self.config = config
62
+ connect(environment, options)
63
+ end
64
+
65
+ def connect(environment, options={})
66
+ raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
67
+ env = config_for_environment(environment)
68
+
69
+ MarkLogic::Connection.configure({
70
+ host: env['host'],
71
+ default_user: env['username'],
72
+ default_password: env['password']
73
+ })
74
+
75
+ MarkLogic::Connection.configure(manage_port: env['manage_port']) if env['manage_port']
76
+ MarkLogic::Connection.configure(admin_port: env['admin_port']) if env['admin_port']
77
+ MarkLogic::Connection.configure(app_services_port: env['app_services_port']) if env['app_services_port']
78
+
79
+ MarkMapper.application = MarkLogic::Application.new(
80
+ "markmapper-application-test",
81
+ connection: MarkLogic::Connection.new(env['host'], env['port'])
82
+ )
83
+ MarkMapper.application.stale?
84
+ end
85
+
86
+ def config_for_environment(environment)
87
+ config[environment.to_s] || {}
88
+ end
59
89
  end
60
90
  end
@@ -12,23 +12,15 @@ module MarkMapper
12
12
  config.mark_mapper = ActiveSupport::OrderedOptions.new
13
13
 
14
14
  # Rescue responses similar to ActiveRecord.
15
- # For rails 3.0 and 3.1
16
- if Rails.version < "3.2"
17
- ActionDispatch::ShowExceptions.rescue_responses['MarkMapper::DocumentNotFound'] = :not_found
18
- ActionDispatch::ShowExceptions.rescue_responses['MarkMapper::InvalidKey'] = :unprocessable_entity
19
- ActionDispatch::ShowExceptions.rescue_responses['MarkMapper::InvalidScheme'] = :unprocessable_entity
20
- ActionDispatch::ShowExceptions.rescue_responses['MarkMapper::NotSupported'] = :unprocessable_entity
21
- else
22
- # For rails 3.2 and 4.0
23
- config.action_dispatch.rescue_responses.merge!(
24
- 'MarkMapper::DocumentNotFound' => :not_found,
25
- 'MarkMapper::InvalidKey' => :unprocessable_entity,
26
- 'MarkMapper::InvalidScheme' => :unprocessable_entity,
27
- 'MarkMapper::NotSupported' => :unprocessable_entity
28
- )
29
- end
15
+ config.action_dispatch.rescue_responses.merge!(
16
+ 'MarkMapper::DocumentNotFound' => :not_found,
17
+ 'MarkMapper::InvalidKey' => :unprocessable_entity,
18
+ 'MarkMapper::InvalidScheme' => :unprocessable_entity,
19
+ 'MarkMapper::NotSupported' => :unprocessable_entity
20
+ )
30
21
 
31
22
  rake_tasks do
23
+ load "mark_mapper/railtie/application.rake"
32
24
  load "mark_mapper/railtie/database.rake"
33
25
  end
34
26
 
@@ -0,0 +1,12 @@
1
+ namespace :app do
2
+ desc 'Drops all the entire application configuration for the current Rails.env'
3
+ task :drop => :environment do
4
+ MarkMapper.application.drop
5
+ end
6
+
7
+ desc 'Creates the application configuration for the current Rails.env'
8
+ task :create => :environment do
9
+ puts "creating application"
10
+ MarkMapper.application.create
11
+ end
12
+ end
@@ -1,8 +1,10 @@
1
1
  namespace :db do
2
2
  unless Rake::Task.task_defined?("db:drop")
3
- desc 'Drops all the collections for the database for the current Rails.env'
3
+ desc 'Drops all the documents for the database for the current Rails.env'
4
4
  task :drop => :environment do
5
- MarkMapper.database.collections.select {|c| c.name !~ /\Asystem\./ }.each(&:drop)
5
+ MarkMapper.application.content_databases.each do |db|
6
+ db.clear
7
+ end
6
8
  end
7
9
  end
8
10
 
@@ -27,7 +29,8 @@ namespace :db do
27
29
 
28
30
  unless Rake::Task.task_defined?("db:create")
29
31
  task :create => :environment do
30
- # noop
32
+ puts "creating database"
33
+ MarkMapper.application.create
31
34
  end
32
35
  end
33
36
 
@@ -54,12 +57,6 @@ namespace :db do
54
57
  end
55
58
  end
56
59
  end
57
-
58
- desc 'Load indexes from db/indexes.rb'
59
- task :index => :environment do
60
- indexes = File.join(Rails.root, 'db', 'indexes.rb')
61
- load(indexes) if File.exist?(indexes)
62
- end
63
60
  end
64
61
 
65
62
  task 'test:prepare' => 'db:test:prepare'
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MarkMapper
3
- Version = '0.0.1'
3
+ Version = '0.0.2'
4
4
  end
@@ -13,6 +13,7 @@ module MarkMapper
13
13
 
14
14
  def create_config_file
15
15
  template 'marklogic.yml', File.join('config', 'marklogic.yml')
16
+ template 'markmapper.rb', File.join('config', 'initializers/markmapper.rb')
16
17
  end
17
18
 
18
19
  protected
@@ -1,19 +1,22 @@
1
1
  defaults: &defaults
2
2
  host: 127.0.0.1
3
- port: 27017
3
+ port: SET YOUR PORT HERE
4
+ # these are the defaults but you can set them here.
5
+ # manage_port: 8002
6
+ # admin_port: 8001
7
+ # app_services_port: 8000
4
8
 
5
9
  development:
6
10
  <<: *defaults
7
- database: <%= database_name || app_name %>_development
11
+ app_name: <%= database_name || app_name %>_development
8
12
 
9
13
  test:
10
14
  <<: *defaults
11
- database: <%= database_name || app_name %>_test
12
- w: 0
15
+ app_name: <%= database_name || app_name %>_test
13
16
 
14
17
  # set these environment variables on your prod server
15
18
  production:
16
19
  <<: *defaults
17
- database: <%= database_name || app_name %>
20
+ app_name: <%= database_name || app_name %>
18
21
  username: <%%= ENV['MARKLOGIC_USERNAME'] %>
19
22
  password: <%%= ENV['MARKLOGIC_PASSWORD'] %>
@@ -0,0 +1,14 @@
1
+ MarkLogic.application.tap do |app|
2
+
3
+ # one way to create a range index. Use this if you want to use MarkMapper's defaults
4
+ # for your database
5
+ # app.add_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:age, :type => 'int'))
6
+
7
+ # If you prefer to have finer control over what settings go into a database
8
+ # you can configure your database(s) like so:
9
+ app.database('my-content-db') do
10
+
11
+ # add range element indexes
12
+ add_range_element_index(MarkLogic::DatabaseSettings::RangeElementIndex.new(:age, :type => 'int'))
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mark_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paxton Hare
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -87,7 +87,6 @@ files:
87
87
  - examples/scopes.rb
88
88
  - examples/validating/embedded_docs.rb
89
89
  - lib/mark_mapper.rb
90
- - lib/mark_mapper/config.rb
91
90
  - lib/mark_mapper/connection.rb
92
91
  - lib/mark_mapper/criteria_hash.rb
93
92
  - lib/mark_mapper/document.rb
@@ -182,11 +181,13 @@ files:
182
181
  - lib/mark_mapper/plugins/validations.rb
183
182
  - lib/mark_mapper/query.rb
184
183
  - lib/mark_mapper/railtie.rb
184
+ - lib/mark_mapper/railtie/application.rake
185
185
  - lib/mark_mapper/railtie/database.rake
186
186
  - lib/mark_mapper/translation.rb
187
187
  - lib/mark_mapper/version.rb
188
188
  - lib/rails/generators/mark_mapper/config/config_generator.rb
189
189
  - lib/rails/generators/mark_mapper/config/templates/marklogic.yml
190
+ - lib/rails/generators/mark_mapper/config/templates/markmapper.rb
190
191
  - lib/rails/generators/mark_mapper/model/model_generator.rb
191
192
  - lib/rails/generators/mark_mapper/model/templates/model.rb
192
193
  - spec/config/mark_mapper.yml
@@ -1,90 +0,0 @@
1
- require 'yaml'
2
-
3
- module MarkMapper
4
-
5
- # This module defines all the configuration options for MarkMapper, including the
6
- # database connections.
7
- module Config
8
- extend self
9
-
10
- def indexes
11
- @indexes ||= []
12
- end
13
-
14
- def settings
15
- @settings ||= {
16
- :host => 'localhost',
17
- :port => 8003,
18
- :manage_port => 8002,
19
- :admin_port => 8001,
20
- :app_name => defined?(Rails) ? Rails::Application.subclasses.first.parent.to_s.underscore : nil,
21
- :username => nil,
22
- :password => nil
23
- }
24
- end
25
-
26
- def application
27
- @application ||=
28
- begin
29
- MarkLogic::Application.new(app_name,
30
- :port => port,
31
- :connection => MarkLogic::Connection.new(host, port))
32
- end
33
- yield(@application) if block_given?
34
- @application
35
- end
36
-
37
- # Load the settings from a compliant mark_mapper.yml file. This can be used for
38
- # easy setup with frameworks other than Rails.
39
- #
40
- # @example Configure MarkMapper.
41
- # MarkMapper.load!("/path/to/mark_mapper.yml")
42
- #
43
- # @param [ String ] path The path to the file.
44
- # @param [ String, Symbol ] environment The environment to load.
45
- #
46
- # @since 0.0.1
47
- def load!(path, environment = nil)
48
- options = load_yaml(path, environment)
49
- load_configuration(options) if options.present?
50
- end
51
-
52
- # From a hash of options, load all the configuration.
53
- #
54
- # @example Load the configuration.
55
- # config.load_configuration(options)
56
- #
57
- # @param [ Hash ] options The configuration options.
58
- #
59
- # @since 0.0.1
60
- def load_configuration(options)
61
- options.each_pair do |key, value|
62
- if settings.has_key? key.to_sym
63
- settings[key.to_sym] = value
64
- else
65
- raise InvalidConfigurationOption, "Invalid configuration item: #{key}"
66
- end
67
- end
68
- end
69
-
70
- def env_name
71
- return Rails.env if defined?(Rails)
72
- ENV["RACK_ENV"] || ENV["MARKMAPPER_ENV"] || raise(Errors::NoEnvironment.new)
73
- end
74
-
75
- def load_yaml(path, environment = nil)
76
- env = environment ? environment.to_s : env_name
77
- YAML.load(ERB.new(File.new(path).read).result)[env]
78
- end
79
-
80
- def method_missing(name, *args)
81
- attr = name.to_s
82
- sym = attr.delete("=").to_sym
83
- if attr.include?("=")
84
- settings[sym] = args.first
85
- else
86
- settings[sym]
87
- end
88
- end
89
- end
90
- end