active_pstore 0.4.9 → 0.4.10

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: 9f3816ea1ca51415462ac3f9e404a002758a3a62
4
- data.tar.gz: 5542b80a872c4321edcc1543dd58202f97073815
3
+ metadata.gz: b8e9351722c286fca7c3d7479e1b0bf92cc76550
4
+ data.tar.gz: 5ab5c558ffaae1f4e6bf6fd9b395dde4d1b8c95d
5
5
  SHA512:
6
- metadata.gz: 4a34726b07509bf18d78c1d7ad56683df663472d5d8f7667d82470532238e3c8f41de902969e690e66633a17980b325cbbef4032e65ba1b4c7152941e486306e
7
- data.tar.gz: 1f64d02dc1bbb0424742faa569385b488216b538d5cbcfef0cb2cd6157a5d4794196e6eb2c9e35faa3702fb169292b057d3e4631c50e28bcd8c4d3385af96388
6
+ metadata.gz: 6652d3af6d54d323985c5fd6b65e07c93f9d88d3833e47318e515bba39cb82bd8f7d0a9ad32256e42482ddcce2ef159a10e61004f3b179b49bd5520e87a48f39
7
+ data.tar.gz: 4c34716b4c75ef5aa4e598f23660d21c56826701c8ad106a0483cef097cc83d14efee74f756b33c0938cbdca1d7b78b1644e74306e7c4ac63e1e4a3c8be8f98a
data/lib/active_pstore.rb CHANGED
@@ -9,6 +9,7 @@ require 'active_pstore/delegation'
9
9
  require 'active_pstore/dynamic_matchers'
10
10
  require 'active_pstore/finder_methods'
11
11
  require 'active_pstore/inheritance'
12
+ require 'active_pstore/integration'
12
13
  require 'active_pstore/model_schema'
13
14
  require 'active_pstore/persistence'
14
15
  require 'active_pstore/query_methods'
@@ -7,5 +7,13 @@ module ActivePStore
7
7
  raise "undefined method `#{attr}'"
8
8
  end
9
9
  end
10
+
11
+ def []=(attr, value)
12
+ if respond_to? "#{attr}=".to_sym
13
+ self.__send__("#{attr}=".to_sym, value)
14
+ else
15
+ raise "undefined method `#{attr}='"
16
+ end
17
+ end
10
18
  end
11
19
  end
@@ -13,6 +13,7 @@ module ActivePStore
13
13
  include ActiveModel::Model
14
14
  include ActivePStore::AttributeMethods
15
15
  include ActivePStore::Core
16
+ include ActivePStore::Integration
16
17
  include ActivePStore::Persistence
17
18
 
18
19
  def initialize(attributes = nil)
@@ -55,6 +56,10 @@ module ActivePStore
55
56
  def find_or_create_by(attributes, &block)
56
57
  find_by(attributes) || create(attributes, &block)
57
58
  end
59
+
60
+ def find_or_initialize_by(attributes, &block)
61
+ find_by(attributes) || new(attributes, &block)
62
+ end
58
63
  end
59
64
  end
60
65
  end
@@ -1,15 +1,14 @@
1
- # encoding: utf-8
2
1
  require 'rails/generators/active_pstore_generator'
3
2
 
4
3
  module Active_Pstore
5
4
  module Generators
6
5
  class ConfigGenerator < Rails::Generators::Base
7
- desc "Creates a Active_Pstore configuration file at config/active_pstore.yml"
6
+ desc 'Creates a Active_Pstore configuration file at config/active_pstore.yml'
8
7
 
9
- argument :database_name, type: :string, optional: true
8
+ # argument :database_name, type: :string, optional: true
10
9
 
11
10
  def self.source_root
12
- @_active_pstore_source_root ||= File.expand_path("../templates", __FILE__)
11
+ @_active_pstore_source_root ||= File.expand_path('../templates', __FILE__)
13
12
  end
14
13
 
15
14
  def app_name
@@ -17,7 +16,7 @@ module Active_Pstore
17
16
  end
18
17
 
19
18
  def create_config_file
20
- template 'active_pstore.yml', File.join('config', "active_pstore.yml")
19
+ template 'active_pstore.yml', File.join('config', 'active_pstore.yml')
21
20
  end
22
21
  end
23
22
  end
@@ -1,135 +1,20 @@
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
1
+ #
2
+ # Ensure the Active PStore gem is defined in your Gemfile
3
+ # gem 'active_pstore'
4
+ #
5
+ default: &default
74
6
 
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
7
+ development:
8
+ <<: *default
9
+ database: db/active_pstore_development.yml
123
10
 
124
- # Ensure all times are UTC in the app side. (default: false)
125
- # use_utc: false
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
- 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
15
+ <<: *default
16
+ database: db/active_pstore_test.yml
17
+
18
+ production:
19
+ <<: *default
20
+ database: db/active_pstore_production.yml
@@ -1,8 +1,9 @@
1
- require "rails/generators/active_pstore_generator"
1
+ require 'rails/generators/active_pstore_generator'
2
2
 
3
3
  module ActivePStore
4
4
  module Generators
5
- class ModelGenerator < Base
5
+ # class ModelGenerator < Base
6
+ class ModelGenerator < Rails::Generators::Base
6
7
 
7
8
  desc "Creates a ActivePStore model"
8
9
  argument :attributes, type: :array, default: [], banner: "attribute attribute"
@@ -14,7 +15,7 @@ module ActivePStore
14
15
  # class_option :collection, type: :string, desc: "The collection for storing model's documents"
15
16
 
16
17
  def create_model_file
17
- template "model.rb.tt", File.join("app/models", class_path, "#{file_name}.rb")
18
+ template 'model.rb.tt', File.join('app/models', class_path, "#{file_name}.rb")
18
19
  end
19
20
 
20
21
  hook_for :test_framework
@@ -1,6 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name %> < ActivePStore::Base
3
- <% attributes.reject {|attr| attr.reference?}.each do |attribute| -%>
3
+ <% attributes.reject {|attr| attr.reference? }.each do |attribute| -%>
4
4
  attr_reader :<%= attribute.name %>
5
5
  <% end -%>
6
6
  end
@@ -26,4 +26,3 @@ module Rails
26
26
  end
27
27
  end
28
28
  =end
29
- end
@@ -0,0 +1,7 @@
1
+ module ActivePStore
2
+ module Integration
3
+ def to_param
4
+ id && id.to_s
5
+ end
6
+ end
7
+ end
@@ -16,6 +16,10 @@ module ActivePStore
16
16
  @id.nil?
17
17
  end
18
18
 
19
+ def persisted?
20
+ !new_record?
21
+ end
22
+
19
23
  def save
20
24
  ActivePStore::Base.use_connection do |connection|
21
25
  if new_record?
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #require "mongoid/railties/document"
3
2
  require 'rails'
4
3
  require 'rails/active_pstore'
@@ -1,3 +1,3 @@
1
1
  module ActivePStore
2
- VERSION = '0.4.9'
2
+ VERSION = '0.4.10'
3
3
  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.9
4
+ version: 0.4.10
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-30 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -78,6 +78,7 @@ files:
78
78
  - lib/active_pstore/generators/active_pstore/model/templates/model.rb.tt
79
79
  - lib/active_pstore/generators/active_pstore_generator.rb
80
80
  - lib/active_pstore/inheritance.rb
81
+ - lib/active_pstore/integration.rb
81
82
  - lib/active_pstore/model_schema.rb
82
83
  - lib/active_pstore/persistence.rb
83
84
  - lib/active_pstore/query_methods.rb