active_pstore 0.4.10 → 0.5.0
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.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/active_pstore/railtie.rb +27 -89
- data/lib/active_pstore/version.rb +1 -1
- data/lib/active_pstore.rb +4 -0
- data/lib/rails/generators/active_pstore/config/config_generator.rb +4 -12
- data/lib/rails/generators/active_pstore/config/templates/active_pstore.yml +17 -132
- data/lib/rails/generators/active_pstore/model/model_generator.rb +7 -9
- metadata +2 -9
- data/lib/active_pstore/generators/active_pstore/config/config_generator.rb +0 -23
- data/lib/active_pstore/generators/active_pstore/config/template/active_pstore.yml +0 -20
- data/lib/active_pstore/generators/active_pstore/model/model_generator.rb +0 -24
- data/lib/active_pstore/generators/active_pstore/model/templates/model.rb.tt +0 -7
- data/lib/active_pstore/generators/active_pstore_generator.rb +0 -28
- data/lib/rails/active_pstore.rb +0 -55
- data/lib/rails/generators/active_pstore_generator.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ddecb64b2c35e955f66716f4d39988c48d4e7bc
|
4
|
+
data.tar.gz: 951efa2d736bbef69a07826bd741f4d2f9742299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ac7cace452785391cb7cc434041f0924521a6af5761de04da193bdefbd3779d72b0d50a415e37b9a3702e96abb6f7d38de828373f5350f771148a3da2aade6
|
7
|
+
data.tar.gz: 2db3e10910cd48e568f6abeb37f7bb2b426b3a5355cc7c4f2de8d49f5007b5aaf7dfa8b1c353b1a88d8f2caa110df7512fbcccc8399603de83a85c2701db3c1e
|
data/README.md
CHANGED
@@ -107,6 +107,37 @@ Artist.where(birth_date: Date.new(1948, 12, 3)..Date.new(1956, 12, 6))
|
|
107
107
|
|
108
108
|
see [spec codes](https://github.com/koic/active_pstore/tree/master/spec) for more information.
|
109
109
|
|
110
|
+
## Integration with Rails
|
111
|
+
|
112
|
+
### Generate config file
|
113
|
+
|
114
|
+
Execute these lines to your Rails application directory:
|
115
|
+
|
116
|
+
```
|
117
|
+
bundle exec rails g active_pstore:config
|
118
|
+
```
|
119
|
+
|
120
|
+
And then create config/active_pstore.yml.
|
121
|
+
|
122
|
+
### Generate model file
|
123
|
+
|
124
|
+
Execute these lines to your Rails application directory:
|
125
|
+
|
126
|
+
```
|
127
|
+
bundle exec rails g active_pstore:model artist name associated_act instrument birth_date
|
128
|
+
```
|
129
|
+
|
130
|
+
And then create app/models/artist.rb
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
class Artist < ActivePStore::Base
|
134
|
+
attr_accessor :name
|
135
|
+
attr_accessor :associated_act
|
136
|
+
attr_accessor :instrument
|
137
|
+
attr_accessor :birth_date
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
110
141
|
## REQUIREMENTS
|
111
142
|
|
112
143
|
* [Active Model](https://github.com/rails/rails/tree/master/activemodel)
|
@@ -1,109 +1,47 @@
|
|
1
|
-
#require "mongoid/railties/document"
|
2
|
-
require 'rails'
|
3
|
-
require 'rails/active_pstore'
|
4
|
-
|
5
1
|
module Rails
|
6
2
|
module ActivePStore
|
7
|
-
|
8
|
-
# Hooks ActivePStore into Rails 3 and higher.
|
9
|
-
#
|
10
|
-
# @since 2.0.0
|
11
3
|
class Railtie < Rails::Railtie
|
12
|
-
|
13
|
-
# Mapping of rescued exceptions to HTTP responses
|
14
|
-
#
|
15
|
-
# @example
|
16
|
-
# railtie.rescue_responses
|
17
|
-
#
|
18
|
-
# @ return [Hash] rescued responses
|
19
|
-
#
|
20
|
-
# @since 2.4.3
|
21
4
|
def self.rescue_responses
|
22
5
|
{
|
23
|
-
'ActivePStore::
|
24
|
-
# "Mongoid::Errors::Validations" => 422
|
6
|
+
'ActivePStore::RecordNotFound' => :not_found
|
25
7
|
}
|
26
8
|
end
|
27
9
|
|
28
|
-
config.app_generators.orm :active_pstore, migration: false
|
29
|
-
|
30
10
|
if config.action_dispatch.rescue_responses
|
31
11
|
config.action_dispatch.rescue_responses.merge!(rescue_responses)
|
32
12
|
end
|
33
13
|
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# @since 2.0.0
|
49
|
-
# config.mongoid = ::Mongoid::Config
|
50
|
-
|
51
|
-
# Initialize Mongoid. This will look for a mongoid.yml in the config
|
52
|
-
# directory and configure mongoid appropriately.
|
53
|
-
#
|
54
|
-
# @since 2.0.0
|
55
|
-
=begin
|
56
|
-
initializer "mongoid.load-config" do
|
57
|
-
config_file = Rails.root.join("config", "mongoid.yml")
|
58
|
-
if config_file.file?
|
59
|
-
begin
|
60
|
-
::Mongoid.load!(config_file)
|
61
|
-
rescue ::Mongoid::Errors::NoClientsConfig => e
|
62
|
-
handle_configuration_error(e)
|
63
|
-
rescue ::Mongoid::Errors::NoDefaultSession => e
|
64
|
-
handle_configuration_error(e)
|
65
|
-
rescue ::Mongoid::Errors::NoSessionDatabase => e
|
66
|
-
handle_configuration_error(e)
|
67
|
-
rescue ::Mongoid::Errors::NoSessionHosts => e
|
68
|
-
handle_configuration_error(e)
|
69
|
-
end
|
14
|
+
# Loads and returns the entire raw configuration of database from
|
15
|
+
# values stored in `config/active_pstore.yml`.
|
16
|
+
def database_configuration
|
17
|
+
yaml = Pathname.new('config/active_pstore.yml')
|
18
|
+
|
19
|
+
config = if yaml && yaml.exist?
|
20
|
+
require 'yaml'
|
21
|
+
require 'erb'
|
22
|
+
YAML.load(ERB.new(yaml.read).result) || {}
|
23
|
+
else
|
24
|
+
raise 'Could not load database configuration. No such file - config/active_pstore.yml'
|
70
25
|
end
|
26
|
+
|
27
|
+
config
|
28
|
+
rescue Psych::SyntaxError => e
|
29
|
+
raise "YAML syntax error occurred while parsing config/active_pstore.yml. " \
|
30
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
31
|
+
"Error: #{e.message}"
|
32
|
+
rescue => e
|
33
|
+
raise e, "Cannot load `Rails::ActivePStore::Railtie.database_configuration`:\n#{e.message}", e.backtrace
|
71
34
|
end
|
72
|
-
=end
|
73
35
|
|
74
|
-
|
75
|
-
|
76
|
-
#
|
77
|
-
# @since 2.0.0
|
78
|
-
# config.after_initialize do
|
79
|
-
# unless config.action_dispatch.rescue_responses
|
80
|
-
# ActionDispatch::ShowExceptions.rescue_responses.update(Railtie.rescue_responses)
|
81
|
-
# end
|
82
|
-
# end
|
36
|
+
initializer 'active_pstore.initialize_database' do
|
37
|
+
config_file = Rails.root.join('config', 'active_pstore.yml')
|
83
38
|
|
84
|
-
|
85
|
-
|
86
|
-
#
|
87
|
-
# This will happen for every request in development, once in other
|
88
|
-
# environments.
|
89
|
-
#
|
90
|
-
# @since 2.0.0
|
91
|
-
# initializer "mongoid.preload-models" do |app|
|
92
|
-
# config.to_prepare do
|
93
|
-
# ::Rails::Mongoid.preload_models(app)
|
94
|
-
# end
|
95
|
-
# end
|
39
|
+
if config_file.file?
|
40
|
+
database = database_configuration.fetch(ENV['RAILS_ENV'] || 'development').fetch('database')
|
96
41
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
# errors and print them out.
|
101
|
-
#
|
102
|
-
# @since 3.0.0
|
103
|
-
# def handle_configuration_error(e)
|
104
|
-
# puts "There is a configuration error with the current mongoid.yml."
|
105
|
-
# puts e.message
|
106
|
-
# end
|
42
|
+
::ActivePStore::Base.establish_connection(database: database)
|
43
|
+
end
|
44
|
+
end
|
107
45
|
end
|
108
46
|
end
|
109
47
|
end
|
data/lib/active_pstore.rb
CHANGED
@@ -1,22 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Active_Pstore
|
1
|
+
module ActivePstore
|
4
2
|
module Generators
|
5
3
|
class ConfigGenerator < Rails::Generators::Base
|
6
|
-
desc
|
7
|
-
|
8
|
-
argument :database_name, type: :string, optional: true
|
4
|
+
desc 'Creates a Active PStore configuration file at config/active_pstore.yml'
|
9
5
|
|
10
6
|
def self.source_root
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def app_name
|
15
|
-
Rails::Application.subclasses.first.parent.to_s.underscore
|
7
|
+
File.expand_path('../templates', __FILE__)
|
16
8
|
end
|
17
9
|
|
18
10
|
def create_config_file
|
19
|
-
template 'active_pstore.yml', File.join('config',
|
11
|
+
template 'active_pstore.yml', File.join('config', 'active_pstore.yml')
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
@@ -1,135 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
1
|
+
#
|
2
|
+
# Ensure the Active PStore gem is defined in your Gemfile
|
3
|
+
# gem 'active_pstore'
|
4
|
+
#
|
5
|
+
default: &default
|
74
6
|
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
7
|
+
development:
|
8
|
+
<<: *default
|
9
|
+
database: db/active_pstore_development.yml
|
123
10
|
|
124
|
-
|
125
|
-
|
11
|
+
# Warning: The database defined as "test" will be erased and
|
12
|
+
# re-generated from your development database when you run "rake".
|
13
|
+
# Do not set this db to the same as development or production.
|
126
14
|
test:
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
read:
|
134
|
-
mode: primary
|
135
|
-
max_pool_size: 1
|
15
|
+
<<: *default
|
16
|
+
database: db/active_pstore_test.yml
|
17
|
+
|
18
|
+
production:
|
19
|
+
<<: *default
|
20
|
+
database: db/active_pstore_production.yml
|
@@ -1,18 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Active_Pstore
|
1
|
+
module ActivePstore
|
4
2
|
module Generators
|
5
|
-
class ModelGenerator <
|
6
|
-
desc 'Creates a
|
7
|
-
argument :attributes, type: :array, default: [], banner: '
|
3
|
+
class ModelGenerator < Rails::Generators::NamedBase
|
4
|
+
desc 'Creates a Active PStore model'
|
5
|
+
argument :attributes, type: :array, default: [], banner: 'attribute_name_1 attribute_name_2'
|
8
6
|
|
9
|
-
|
7
|
+
def self.source_root
|
8
|
+
File.expand_path('../templates', __FILE__)
|
9
|
+
end
|
10
10
|
|
11
11
|
def create_model_file
|
12
12
|
template 'model.rb.tt', File.join('app/models', class_path, "#{file_name}.rb")
|
13
13
|
end
|
14
|
-
|
15
|
-
hook_for :test_framework
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_pstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
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-09-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -72,11 +72,6 @@ files:
|
|
72
72
|
- lib/active_pstore/dynamic_matchers.rb
|
73
73
|
- lib/active_pstore/errors.rb
|
74
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
|
80
75
|
- lib/active_pstore/inheritance.rb
|
81
76
|
- lib/active_pstore/integration.rb
|
82
77
|
- lib/active_pstore/model_schema.rb
|
@@ -85,12 +80,10 @@ files:
|
|
85
80
|
- lib/active_pstore/querying.rb
|
86
81
|
- lib/active_pstore/railtie.rb
|
87
82
|
- lib/active_pstore/version.rb
|
88
|
-
- lib/rails/active_pstore.rb
|
89
83
|
- lib/rails/generators/active_pstore/config/config_generator.rb
|
90
84
|
- lib/rails/generators/active_pstore/config/templates/active_pstore.yml
|
91
85
|
- lib/rails/generators/active_pstore/model/model_generator.rb
|
92
86
|
- lib/rails/generators/active_pstore/model/templates/model.rb.tt
|
93
|
-
- lib/rails/generators/active_pstore_generator.rb
|
94
87
|
homepage: http://github.com/koic/active_pstore
|
95
88
|
licenses:
|
96
89
|
- MIT
|
@@ -1,23 +0,0 @@
|
|
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
|
@@ -1,20 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ensure the Active PStore gem is defined in your Gemfile
|
3
|
-
# gem 'active_pstore'
|
4
|
-
#
|
5
|
-
default: &default
|
6
|
-
|
7
|
-
development:
|
8
|
-
<<: *default
|
9
|
-
database: db/active_pstore_development.yml
|
10
|
-
|
11
|
-
# Warning: The database defined as "test" will be erased and
|
12
|
-
# re-generated from your development database when you run "rake".
|
13
|
-
# Do not set this db to the same as development or production.
|
14
|
-
test:
|
15
|
-
<<: *default
|
16
|
-
database: db/active_pstore_test.yml
|
17
|
-
|
18
|
-
production:
|
19
|
-
<<: *default
|
20
|
-
database: db/active_pstore_production.yml
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rails/generators/active_pstore_generator'
|
2
|
-
|
3
|
-
module ActivePStore
|
4
|
-
module Generators
|
5
|
-
# class ModelGenerator < Base
|
6
|
-
class ModelGenerator < Rails::Generators::Base
|
7
|
-
|
8
|
-
desc "Creates a ActivePStore model"
|
9
|
-
argument :attributes, type: :array, default: [], banner: "attribute attribute"
|
10
|
-
|
11
|
-
check_class_collision
|
12
|
-
|
13
|
-
# class_option :timestamps, type: :boolean
|
14
|
-
# class_option :parent, type: :string, desc: "The parent class for the generated model"
|
15
|
-
# class_option :collection, type: :string, desc: "The collection for storing model's documents"
|
16
|
-
|
17
|
-
def create_model_file
|
18
|
-
template 'model.rb.tt', File.join('app/models', class_path, "#{file_name}.rb")
|
19
|
-
end
|
20
|
-
|
21
|
-
hook_for :test_framework
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,28 +0,0 @@
|
|
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
|
data/lib/rails/active_pstore.rb
DELETED
@@ -1,55 +0,0 @@
|
|
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
|
@@ -1,28 +0,0 @@
|
|
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
|