active_pstore 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.md +2 -2
- data/README.md +2 -2
- data/lib/active_pstore/attribute_methods.rb +11 -0
- data/lib/active_pstore/base.rb +19 -9
- data/lib/active_pstore/connection_handling.rb +7 -1
- data/lib/active_pstore/generators/active_pstore/config/config_generator.rb +24 -0
- data/lib/active_pstore/generators/active_pstore/config/template/active_pstore.yml +135 -0
- data/lib/active_pstore/generators/active_pstore/model/model_generator.rb +23 -0
- data/lib/active_pstore/generators/active_pstore/model/templates/model.rb.tt +7 -0
- data/lib/active_pstore/generators/active_pstore_generator.rb +29 -0
- data/lib/active_pstore/querying.rb +4 -10
- data/lib/active_pstore/railtie.rb +110 -0
- data/lib/active_pstore/version.rb +1 -1
- data/lib/active_pstore.rb +1 -0
- data/lib/rails/active_pstore.rb +55 -0
- data/lib/rails/generators/active_pstore/config/config_generator.rb +23 -0
- data/lib/rails/generators/active_pstore/config/templates/active_pstore.yml +135 -0
- data/lib/rails/generators/active_pstore/model/model_generator.rb +18 -0
- data/lib/rails/generators/active_pstore/model/templates/model.rb.tt +7 -0
- data/lib/rails/generators/active_pstore_generator.rb +28 -0
- metadata +29 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3816ea1ca51415462ac3f9e404a002758a3a62
|
4
|
+
data.tar.gz: 5542b80a872c4321edcc1543dd58202f97073815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a34726b07509bf18d78c1d7ad56683df663472d5d8f7667d82470532238e3c8f41de902969e690e66633a17980b325cbbef4032e65ba1b4c7152941e486306e
|
7
|
+
data.tar.gz: 1f64d02dc1bbb0424742faa569385b488216b538d5cbcfef0cb2cd6157a5d4794196e6eb2c9e35faa3702fb169292b057d3e4631c50e28bcd8c4d3385af96388
|
data/README.ja.md
CHANGED
@@ -40,7 +40,7 @@ randy_rhoads = Artist.new(name: 'Randy Rhoads')
|
|
40
40
|
```ruby
|
41
41
|
randy_rhoads = Artist.new {|a|
|
42
42
|
a.name = 'Randy Rhoads'
|
43
|
-
|
43
|
+
}
|
44
44
|
```
|
45
45
|
|
46
46
|
`ActivePStore::Base.new` メソッドと別名として `ActivePStore::Base.build` を使うこともできます。
|
@@ -110,7 +110,7 @@ Artist.where(birth_date: Date.new(1948, 12, 3)..Date.new(1956, 12, 6))
|
|
110
110
|
|
111
111
|
## REQUIREMENTS
|
112
112
|
|
113
|
-
*
|
113
|
+
* [Active Model](https://github.com/rails/rails/tree/master/activemodel)
|
114
114
|
|
115
115
|
## INSTALL
|
116
116
|
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ or
|
|
39
39
|
```ruby
|
40
40
|
randy_rhoads = Artist.new {|a|
|
41
41
|
a.name = 'Randy Rhoads'
|
42
|
-
|
42
|
+
}
|
43
43
|
```
|
44
44
|
|
45
45
|
`ActivePStore::Base.build` method the same as `ActivePStore::Base.new` method.
|
@@ -109,7 +109,7 @@ see [spec codes](https://github.com/koic/active_pstore/tree/master/spec) for mor
|
|
109
109
|
|
110
110
|
## REQUIREMENTS
|
111
111
|
|
112
|
-
|
112
|
+
* [Active Model](https://github.com/rails/rails/tree/master/activemodel)
|
113
113
|
|
114
114
|
## INSTALL
|
115
115
|
|
data/lib/active_pstore/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
1
3
|
module ActivePStore
|
2
4
|
class Base
|
3
5
|
extend ActivePStore::ConnectionHandling
|
@@ -8,15 +10,19 @@ module ActivePStore
|
|
8
10
|
extend ActivePStore::QueryMethods
|
9
11
|
extend ActivePStore::Querying
|
10
12
|
extend ActivePStore::Delegation
|
13
|
+
include ActiveModel::Model
|
14
|
+
include ActivePStore::AttributeMethods
|
11
15
|
include ActivePStore::Core
|
12
16
|
include ActivePStore::Persistence
|
13
17
|
|
14
|
-
def initialize(attributes =
|
15
|
-
attributes.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def initialize(attributes = nil)
|
19
|
+
if attributes.present?
|
20
|
+
attributes.each do |attr, val|
|
21
|
+
if respond_to? "#{attr}=".to_sym
|
22
|
+
self.__send__("#{attr}=", val)
|
23
|
+
else
|
24
|
+
raise "undefined method `#{attr}='"
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
@@ -32,9 +38,9 @@ module ActivePStore
|
|
32
38
|
}
|
33
39
|
end
|
34
40
|
|
35
|
-
def create(attributes =
|
41
|
+
def create(attributes = nil, &block)
|
36
42
|
if attributes.is_a?(Array)
|
37
|
-
attributes.map {|
|
43
|
+
attributes.map {|attr| create(attr, &block) }
|
38
44
|
else
|
39
45
|
build(attributes, &block).tap do |obj|
|
40
46
|
obj.save
|
@@ -42,9 +48,13 @@ module ActivePStore
|
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
|
-
def first_or_create(attributes =
|
51
|
+
def first_or_create(attributes = nil, &block)
|
46
52
|
first || create(attributes, &block)
|
47
53
|
end
|
54
|
+
|
55
|
+
def find_or_create_by(attributes, &block)
|
56
|
+
find_by(attributes) || create(attributes, &block)
|
57
|
+
end
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
@@ -2,12 +2,18 @@ require 'pstore'
|
|
2
2
|
|
3
3
|
module ActivePStore
|
4
4
|
module ConnectionHandling
|
5
|
+
def connection_config
|
6
|
+
@@config.dup.freeze
|
7
|
+
end
|
8
|
+
|
5
9
|
def establish_connection(options)
|
6
10
|
unless options.is_a? Hash
|
7
11
|
raise ArgumentError, "You must specify at database configuration. Example: ActivePStore::Base.establish_connection(database: '/path/to/file')"
|
8
12
|
end
|
9
13
|
|
10
|
-
@@
|
14
|
+
@@config = {database: (options[:database] || options['database']).to_s}
|
15
|
+
|
16
|
+
@@db = PStore.new(@@config[:database])
|
11
17
|
end
|
12
18
|
|
13
19
|
def use_connection
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails/generators/active_pstore_generator'
|
3
|
+
|
4
|
+
module Active_Pstore
|
5
|
+
module Generators
|
6
|
+
class ConfigGenerator < Rails::Generators::Base
|
7
|
+
desc "Creates a Active_Pstore configuration file at config/active_pstore.yml"
|
8
|
+
|
9
|
+
argument :database_name, type: :string, optional: true
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
@_active_pstore_source_root ||= File.expand_path("../templates", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_name
|
16
|
+
Rails::Application.subclasses.first.parent.to_s.underscore
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_config_file
|
20
|
+
template 'active_pstore.yml', File.join('config', "active_pstore.yml")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
development:
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: <%= database_name || app_name %>_development
|
9
|
+
# Provides the hosts the default client can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
options:
|
14
|
+
# Change the default write concern. (default = { w: 1 })
|
15
|
+
# write:
|
16
|
+
# w: 1
|
17
|
+
|
18
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
19
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
20
|
+
# (default: primary)
|
21
|
+
# read:
|
22
|
+
# mode: :secondary_preferred
|
23
|
+
|
24
|
+
# The name of the user for authentication.
|
25
|
+
# user: 'user'
|
26
|
+
|
27
|
+
# The password of the user for authentication.
|
28
|
+
# password: 'password'
|
29
|
+
|
30
|
+
# The user's database roles.
|
31
|
+
# roles:
|
32
|
+
# - 'dbOwner'
|
33
|
+
|
34
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
35
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
36
|
+
# on 2.4 and 2.6 is :plain)
|
37
|
+
# auth_mech: :scram
|
38
|
+
|
39
|
+
# The database or source to authenticate the user against. (default: admin)
|
40
|
+
# auth_source: admin
|
41
|
+
|
42
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
43
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
44
|
+
# when connecting to hidden members of a replica set.
|
45
|
+
# connect: :direct
|
46
|
+
|
47
|
+
# Changes the default time in seconds the server monitors refresh their status
|
48
|
+
# via ismaster commands. (default: 10)
|
49
|
+
# heartbeat_frequency: 10
|
50
|
+
|
51
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
52
|
+
# local_threshold: 5
|
53
|
+
|
54
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
55
|
+
# server_selection_timeout: 30
|
56
|
+
|
57
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
58
|
+
# max_pool_size: 5
|
59
|
+
|
60
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
61
|
+
# min_pool_size: 1
|
62
|
+
|
63
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
64
|
+
# to be checked in before timing out. (default: 5)
|
65
|
+
# wait_queue_timeout: 5
|
66
|
+
|
67
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
68
|
+
# (default: 5)
|
69
|
+
# connect_timeout: 5
|
70
|
+
|
71
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
72
|
+
# (default: 5)
|
73
|
+
# socket_timeout: 5
|
74
|
+
|
75
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
76
|
+
# not belong to this replica set will be ignored.
|
77
|
+
# replica_set: name
|
78
|
+
|
79
|
+
# Whether to connect to the servers via ssl. (default: false)
|
80
|
+
# ssl: true
|
81
|
+
|
82
|
+
# The certificate file used to identify the connection against MongoDB.
|
83
|
+
# ssl_cert: /path/to/my.cert
|
84
|
+
|
85
|
+
# The private keyfile used to identify the connection against MongoDB.
|
86
|
+
# Note that even if the key is stored in the same file as the certificate,
|
87
|
+
# both need to be explicitly specified.
|
88
|
+
# ssl_key: /path/to/my.key
|
89
|
+
|
90
|
+
# A passphrase for the private key.
|
91
|
+
# ssl_key_pass_phrase: password
|
92
|
+
|
93
|
+
# Whether or not to do peer certification validation. (default: false)
|
94
|
+
# ssl_verify: true
|
95
|
+
|
96
|
+
# The file containing a set of concatenated certification authority certifications
|
97
|
+
# used to validate certs passed from the other end of the connection.
|
98
|
+
# ssl_ca_cert: /path/to/ca.cert
|
99
|
+
|
100
|
+
|
101
|
+
# Configure Mongoid specific options. (optional)
|
102
|
+
options:
|
103
|
+
# Includes the root model name in json serialization. (default: false)
|
104
|
+
# include_root_in_json: false
|
105
|
+
|
106
|
+
# Include the _type field in serialization. (default: false)
|
107
|
+
# include_type_for_serialization: false
|
108
|
+
|
109
|
+
# Preload all models in development, needed when models use
|
110
|
+
# inheritance. (default: false)
|
111
|
+
# preload_models: false
|
112
|
+
|
113
|
+
# Raise an error when performing a #find and the document is not found.
|
114
|
+
# (default: true)
|
115
|
+
# raise_not_found_error: true
|
116
|
+
|
117
|
+
# Raise an error when defining a scope with the same name as an
|
118
|
+
# existing method. (default: false)
|
119
|
+
# scope_overwrite_exception: false
|
120
|
+
|
121
|
+
# Use Active Support's time zone in conversions. (default: true)
|
122
|
+
# use_activesupport_time_zone: true
|
123
|
+
|
124
|
+
# Ensure all times are UTC in the app side. (default: false)
|
125
|
+
# use_utc: false
|
126
|
+
test:
|
127
|
+
clients:
|
128
|
+
default:
|
129
|
+
database: <%= database_name || app_name %>_test
|
130
|
+
hosts:
|
131
|
+
- localhost:27017
|
132
|
+
options:
|
133
|
+
read:
|
134
|
+
mode: primary
|
135
|
+
max_pool_size: 1
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "rails/generators/active_pstore_generator"
|
2
|
+
|
3
|
+
module ActivePStore
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
|
7
|
+
desc "Creates a ActivePStore model"
|
8
|
+
argument :attributes, type: :array, default: [], banner: "attribute attribute"
|
9
|
+
|
10
|
+
check_class_collision
|
11
|
+
|
12
|
+
# class_option :timestamps, type: :boolean
|
13
|
+
# class_option :parent, type: :string, desc: "The parent class for the generated model"
|
14
|
+
# class_option :collection, type: :string, desc: "The collection for storing model's documents"
|
15
|
+
|
16
|
+
def create_model_file
|
17
|
+
template "model.rb.tt", File.join("app/models", class_path, "#{file_name}.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
hook_for :test_framework
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
require "rails/generators/active_model"
|
3
|
+
|
4
|
+
module ActivePStore
|
5
|
+
module Generators
|
6
|
+
class Base < ::Rails::Generators::NamedBase
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@_active_pstore_source_root ||=
|
10
|
+
File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
=begin
|
17
|
+
module Rails
|
18
|
+
module Generators
|
19
|
+
class GeneratedAttribute
|
20
|
+
def type_class
|
21
|
+
return "Time" if type == :datetime
|
22
|
+
return "String" if type == :text
|
23
|
+
return "Mongoid::Boolean" if type == :boolean
|
24
|
+
type.to_s.camelcase
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
=end
|
29
|
+
end
|
@@ -1,15 +1,9 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module ActivePStore
|
2
4
|
module Querying
|
3
|
-
|
4
|
-
all.update_all(updates)
|
5
|
-
end
|
6
|
-
|
7
|
-
def destroy_all
|
8
|
-
all.destroy_all
|
9
|
-
end
|
5
|
+
extend Forwardable
|
10
6
|
|
11
|
-
|
12
|
-
all.count
|
13
|
-
end
|
7
|
+
def_delegators :all, :update_all, :destroy_all, :count
|
14
8
|
end
|
15
9
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#require "mongoid/railties/document"
|
3
|
+
require 'rails'
|
4
|
+
require 'rails/active_pstore'
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
module ActivePStore
|
8
|
+
|
9
|
+
# Hooks ActivePStore into Rails 3 and higher.
|
10
|
+
#
|
11
|
+
# @since 2.0.0
|
12
|
+
class Railtie < Rails::Railtie
|
13
|
+
|
14
|
+
# Mapping of rescued exceptions to HTTP responses
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# railtie.rescue_responses
|
18
|
+
#
|
19
|
+
# @ return [Hash] rescued responses
|
20
|
+
#
|
21
|
+
# @since 2.4.3
|
22
|
+
def self.rescue_responses
|
23
|
+
{
|
24
|
+
'ActivePStore::Errors::RecordNotFound' => :not_found
|
25
|
+
# "Mongoid::Errors::Validations" => 422
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
config.app_generators.orm :active_pstore, migration: false
|
30
|
+
|
31
|
+
if config.action_dispatch.rescue_responses
|
32
|
+
config.action_dispatch.rescue_responses.merge!(rescue_responses)
|
33
|
+
end
|
34
|
+
|
35
|
+
# rake_tasks do
|
36
|
+
# load "mongoid/railties/database.rake"
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Exposes Mongoid's configuration to the Rails application configuration.
|
40
|
+
#
|
41
|
+
# @example Set up configuration in the Rails app.
|
42
|
+
# module MyApplication
|
43
|
+
# class Application < Rails::Application
|
44
|
+
# config.mongoid.logger = Logger.new($stdout, :warn)
|
45
|
+
# config.mongoid.persist_in_safe_mode = true
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# @since 2.0.0
|
50
|
+
# config.mongoid = ::Mongoid::Config
|
51
|
+
|
52
|
+
# Initialize Mongoid. This will look for a mongoid.yml in the config
|
53
|
+
# directory and configure mongoid appropriately.
|
54
|
+
#
|
55
|
+
# @since 2.0.0
|
56
|
+
=begin
|
57
|
+
initializer "mongoid.load-config" do
|
58
|
+
config_file = Rails.root.join("config", "mongoid.yml")
|
59
|
+
if config_file.file?
|
60
|
+
begin
|
61
|
+
::Mongoid.load!(config_file)
|
62
|
+
rescue ::Mongoid::Errors::NoClientsConfig => e
|
63
|
+
handle_configuration_error(e)
|
64
|
+
rescue ::Mongoid::Errors::NoDefaultSession => e
|
65
|
+
handle_configuration_error(e)
|
66
|
+
rescue ::Mongoid::Errors::NoSessionDatabase => e
|
67
|
+
handle_configuration_error(e)
|
68
|
+
rescue ::Mongoid::Errors::NoSessionHosts => e
|
69
|
+
handle_configuration_error(e)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
=end
|
74
|
+
|
75
|
+
# Set the proper error types for Rails. DocumentNotFound errors should be
|
76
|
+
# 404s and not 500s, validation errors are 422s.
|
77
|
+
#
|
78
|
+
# @since 2.0.0
|
79
|
+
# config.after_initialize do
|
80
|
+
# unless config.action_dispatch.rescue_responses
|
81
|
+
# ActionDispatch::ShowExceptions.rescue_responses.update(Railtie.rescue_responses)
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
|
85
|
+
# Due to all models not getting loaded and messing up inheritance queries
|
86
|
+
# and indexing, we need to preload the models in order to address this.
|
87
|
+
#
|
88
|
+
# This will happen for every request in development, once in other
|
89
|
+
# environments.
|
90
|
+
#
|
91
|
+
# @since 2.0.0
|
92
|
+
# initializer "mongoid.preload-models" do |app|
|
93
|
+
# config.to_prepare do
|
94
|
+
# ::Rails::Mongoid.preload_models(app)
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
|
98
|
+
# Rails runs all initializers first before getting into any generator
|
99
|
+
# code, so we have no way in the intitializer to know if we are
|
100
|
+
# generating a mongoid.yml. So instead of failing, we catch all the
|
101
|
+
# errors and print them out.
|
102
|
+
#
|
103
|
+
# @since 3.0.0
|
104
|
+
# def handle_configuration_error(e)
|
105
|
+
# puts "There is a configuration error with the current mongoid.yml."
|
106
|
+
# puts e.message
|
107
|
+
# end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/active_pstore.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Rails
|
2
|
+
module ActivePStore
|
3
|
+
extend self
|
4
|
+
|
5
|
+
# Use the application configuration to get every model and require it, so
|
6
|
+
# that indexing and inheritance work in both development and production
|
7
|
+
# with the same results.
|
8
|
+
#
|
9
|
+
# @example Load all the application models.
|
10
|
+
# Rails::Mongoid.load_models(app)
|
11
|
+
#
|
12
|
+
# @param [ Application ] app The rails application.
|
13
|
+
def load_models(app)
|
14
|
+
app.config.paths['app/models'].expanded.each do |path|
|
15
|
+
preload = ::ActivePStore.preload_models
|
16
|
+
if preload.resizable?
|
17
|
+
files = preload.map {|model| "#{path}/#{model.underscore}.rb" }
|
18
|
+
else
|
19
|
+
files = Dir.glob("#{path}/**/*.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
files.sort.each do |file|
|
23
|
+
load_model(file.gsub("#{path}/" , "").gsub(".rb", ""))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Conditionally calls `Rails::Mongoid.load_models(app)` if the
|
29
|
+
# `::Mongoid.preload_models` is `true`.
|
30
|
+
#
|
31
|
+
# @param [ Application ] app The rails application.
|
32
|
+
def preload_models(app)
|
33
|
+
load_models(app) if ::ActivePStore.preload_models
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# I don't want to mock out kernel for unit testing purposes, so added this
|
39
|
+
# method as a convenience.
|
40
|
+
#
|
41
|
+
# @example Load the model.
|
42
|
+
# Mongoid.load_model("/mongoid/behaviour")
|
43
|
+
#
|
44
|
+
# @param [ String ] file The base filename.
|
45
|
+
#
|
46
|
+
# @since 2.0.0.rc.3
|
47
|
+
def load_model(file)
|
48
|
+
begin
|
49
|
+
require_dependency(file)
|
50
|
+
rescue Exception => e
|
51
|
+
Logger.new($stdout).warn(e.message)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/active_pstore_generator'
|
2
|
+
|
3
|
+
module Active_Pstore
|
4
|
+
module Generators
|
5
|
+
class ConfigGenerator < Rails::Generators::Base
|
6
|
+
desc "Creates a Active_Pstore configuration file at config/active_pstore.yml"
|
7
|
+
|
8
|
+
argument :database_name, type: :string, optional: true
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
@_active_pstore_source_root ||= File.expand_path("../templates", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def app_name
|
15
|
+
Rails::Application.subclasses.first.parent.to_s.underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_config_file
|
19
|
+
template 'active_pstore.yml', File.join('config', "active_pstore.yml")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
development:
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: <%= database_name || app_name %>_development
|
9
|
+
# Provides the hosts the default client can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
options:
|
14
|
+
# Change the default write concern. (default = { w: 1 })
|
15
|
+
# write:
|
16
|
+
# w: 1
|
17
|
+
|
18
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
19
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
20
|
+
# (default: primary)
|
21
|
+
# read:
|
22
|
+
# mode: :secondary_preferred
|
23
|
+
|
24
|
+
# The name of the user for authentication.
|
25
|
+
# user: 'user'
|
26
|
+
|
27
|
+
# The password of the user for authentication.
|
28
|
+
# password: 'password'
|
29
|
+
|
30
|
+
# The user's database roles.
|
31
|
+
# roles:
|
32
|
+
# - 'dbOwner'
|
33
|
+
|
34
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
35
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
36
|
+
# on 2.4 and 2.6 is :plain)
|
37
|
+
# auth_mech: :scram
|
38
|
+
|
39
|
+
# The database or source to authenticate the user against. (default: admin)
|
40
|
+
# auth_source: admin
|
41
|
+
|
42
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
43
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
44
|
+
# when connecting to hidden members of a replica set.
|
45
|
+
# connect: :direct
|
46
|
+
|
47
|
+
# Changes the default time in seconds the server monitors refresh their status
|
48
|
+
# via ismaster commands. (default: 10)
|
49
|
+
# heartbeat_frequency: 10
|
50
|
+
|
51
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
52
|
+
# local_threshold: 5
|
53
|
+
|
54
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
55
|
+
# server_selection_timeout: 30
|
56
|
+
|
57
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
58
|
+
# max_pool_size: 5
|
59
|
+
|
60
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
61
|
+
# min_pool_size: 1
|
62
|
+
|
63
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
64
|
+
# to be checked in before timing out. (default: 5)
|
65
|
+
# wait_queue_timeout: 5
|
66
|
+
|
67
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
68
|
+
# (default: 5)
|
69
|
+
# connect_timeout: 5
|
70
|
+
|
71
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
72
|
+
# (default: 5)
|
73
|
+
# socket_timeout: 5
|
74
|
+
|
75
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
76
|
+
# not belong to this replica set will be ignored.
|
77
|
+
# replica_set: name
|
78
|
+
|
79
|
+
# Whether to connect to the servers via ssl. (default: false)
|
80
|
+
# ssl: true
|
81
|
+
|
82
|
+
# The certificate file used to identify the connection against MongoDB.
|
83
|
+
# ssl_cert: /path/to/my.cert
|
84
|
+
|
85
|
+
# The private keyfile used to identify the connection against MongoDB.
|
86
|
+
# Note that even if the key is stored in the same file as the certificate,
|
87
|
+
# both need to be explicitly specified.
|
88
|
+
# ssl_key: /path/to/my.key
|
89
|
+
|
90
|
+
# A passphrase for the private key.
|
91
|
+
# ssl_key_pass_phrase: password
|
92
|
+
|
93
|
+
# Whether or not to do peer certification validation. (default: false)
|
94
|
+
# ssl_verify: true
|
95
|
+
|
96
|
+
# The file containing a set of concatenated certification authority certifications
|
97
|
+
# used to validate certs passed from the other end of the connection.
|
98
|
+
# ssl_ca_cert: /path/to/ca.cert
|
99
|
+
|
100
|
+
|
101
|
+
# Configure Mongoid specific options. (optional)
|
102
|
+
options:
|
103
|
+
# Includes the root model name in json serialization. (default: false)
|
104
|
+
# include_root_in_json: false
|
105
|
+
|
106
|
+
# Include the _type field in serialization. (default: false)
|
107
|
+
# include_type_for_serialization: false
|
108
|
+
|
109
|
+
# Preload all models in development, needed when models use
|
110
|
+
# inheritance. (default: false)
|
111
|
+
# preload_models: false
|
112
|
+
|
113
|
+
# Raise an error when performing a #find and the document is not found.
|
114
|
+
# (default: true)
|
115
|
+
# raise_not_found_error: true
|
116
|
+
|
117
|
+
# Raise an error when defining a scope with the same name as an
|
118
|
+
# existing method. (default: false)
|
119
|
+
# scope_overwrite_exception: false
|
120
|
+
|
121
|
+
# Use Active Support's time zone in conversions. (default: true)
|
122
|
+
# use_activesupport_time_zone: true
|
123
|
+
|
124
|
+
# Ensure all times are UTC in the app side. (default: false)
|
125
|
+
# use_utc: false
|
126
|
+
test:
|
127
|
+
clients:
|
128
|
+
default:
|
129
|
+
database: <%= database_name || app_name %>_test
|
130
|
+
hosts:
|
131
|
+
- localhost:27017
|
132
|
+
options:
|
133
|
+
read:
|
134
|
+
mode: primary
|
135
|
+
max_pool_size: 1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/active_pstore_generator'
|
2
|
+
|
3
|
+
module Active_Pstore
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
desc 'Creates a ActivePStore model'
|
7
|
+
argument :attributes, type: :array, default: [], banner: 'attribute_name attribute_name'
|
8
|
+
|
9
|
+
check_class_collision
|
10
|
+
|
11
|
+
def create_model_file
|
12
|
+
template 'model.rb.tt', File.join('app/models', class_path, "#{file_name}.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
hook_for :test_framework
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'rails/generators/active_model'
|
3
|
+
|
4
|
+
module Active_Pstore
|
5
|
+
module Generators
|
6
|
+
class Base < ::Rails::Generators::NamedBase
|
7
|
+
def self.source_root
|
8
|
+
@_active_pstore_source_root ||=
|
9
|
+
File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
=begin
|
16
|
+
module Rails
|
17
|
+
module Generators
|
18
|
+
class GeneratedAttribute
|
19
|
+
def type_class
|
20
|
+
return "Time" if type == :datetime
|
21
|
+
return "String" if type == :text
|
22
|
+
return "Mongoid::Boolean" if type == :boolean
|
23
|
+
type.to_s.camelcase
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
=end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_pstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi ITO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: codeclimate-test-reporter
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,6 +62,7 @@ files:
|
|
48
62
|
- README.ja.md
|
49
63
|
- README.md
|
50
64
|
- lib/active_pstore.rb
|
65
|
+
- lib/active_pstore/attribute_methods.rb
|
51
66
|
- lib/active_pstore/base.rb
|
52
67
|
- lib/active_pstore/calculations.rb
|
53
68
|
- lib/active_pstore/collection.rb
|
@@ -57,12 +72,24 @@ files:
|
|
57
72
|
- lib/active_pstore/dynamic_matchers.rb
|
58
73
|
- lib/active_pstore/errors.rb
|
59
74
|
- lib/active_pstore/finder_methods.rb
|
75
|
+
- lib/active_pstore/generators/active_pstore/config/config_generator.rb
|
76
|
+
- lib/active_pstore/generators/active_pstore/config/template/active_pstore.yml
|
77
|
+
- lib/active_pstore/generators/active_pstore/model/model_generator.rb
|
78
|
+
- lib/active_pstore/generators/active_pstore/model/templates/model.rb.tt
|
79
|
+
- lib/active_pstore/generators/active_pstore_generator.rb
|
60
80
|
- lib/active_pstore/inheritance.rb
|
61
81
|
- lib/active_pstore/model_schema.rb
|
62
82
|
- lib/active_pstore/persistence.rb
|
63
83
|
- lib/active_pstore/query_methods.rb
|
64
84
|
- lib/active_pstore/querying.rb
|
85
|
+
- lib/active_pstore/railtie.rb
|
65
86
|
- lib/active_pstore/version.rb
|
87
|
+
- lib/rails/active_pstore.rb
|
88
|
+
- lib/rails/generators/active_pstore/config/config_generator.rb
|
89
|
+
- lib/rails/generators/active_pstore/config/templates/active_pstore.yml
|
90
|
+
- lib/rails/generators/active_pstore/model/model_generator.rb
|
91
|
+
- lib/rails/generators/active_pstore/model/templates/model.rb.tt
|
92
|
+
- lib/rails/generators/active_pstore_generator.rb
|
66
93
|
homepage: http://github.com/koic/active_pstore
|
67
94
|
licenses:
|
68
95
|
- MIT
|