fish0 0.0.5 → 0.0.6

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: c4ea27a40ff37fcc325b73bb219e76a5e23aeadb
4
- data.tar.gz: 8492357144680757b2f7a31a5ff5d3417eb49785
3
+ metadata.gz: af0d8c5d6b6d9c34b27abe4e2d6c9e6a56332a34
4
+ data.tar.gz: 61709857c463321cfa11b987d01420c1d1cf2a43
5
5
  SHA512:
6
- metadata.gz: eaacc7b77a8d7b5744129b884aeef8278c3912f5b0f21d213986314240bf700ed36fbe18c3b76b46a961a22ec0815c8acedd55820847cb39dbc175396a7481a0
7
- data.tar.gz: 5e5a584979c2488dfbabeb21130e52692363d1d6f46d957839e088d461b6fd52b10bafa0ccb36492d4c3eacaebaa611b59e867a32d4fadbc4a669155cc02c435
6
+ metadata.gz: 28fbf425d5d62dfd31966a701a7bbb093aec2f27bde60c6f3b73b5349ab26593adb54d1797db5a5fb8e37fea0d0987f94230f703a7f5ed99ef999ccb9970153a
7
+ data.tar.gz: 009725b2871b44eb8adfca8e2ea0eee43afd8093ebd11405e81f68bcdb67ec25275dc78ecd084d4bc5bd1e45ad34bdf3e1132bbba450fcedefe77b919e4730da
@@ -0,0 +1,21 @@
1
+ module Fish0
2
+ class Collection < Array
3
+ def cache_key
4
+ most_recent = select(&:updated_at).sort_by(&:updated_at).last
5
+
6
+ timestamp = time_to_string(most_recent ? most_recent.updated_at : Time.zone.now)
7
+
8
+ "#{objects_key}-#{timestamp}"
9
+ end
10
+
11
+ protected
12
+
13
+ def objects_key
14
+ Digest::MD5.hexdigest(map(&:slug).join)
15
+ end
16
+
17
+ def time_to_string(timestamp)
18
+ timestamp.strftime('%Y%m%d%H%M%S%9N')
19
+ end
20
+ end
21
+ end
@@ -50,8 +50,8 @@ module Fish0
50
50
  end
51
51
 
52
52
  def repository
53
- if "#{entity.to_s}Repository".safe_constantize
54
- return "#{entity.to_s}Repository".constantize.new(collection, entity)
53
+ if "#{entity}Repository".safe_constantize
54
+ return "#{entity}Repository".constantize.new(collection, entity)
55
55
  end
56
56
  Fish0::Repository.new(collection, entity)
57
57
  end
@@ -0,0 +1,29 @@
1
+ module Fish0
2
+ ##
3
+ # Fish0::Configuration
4
+ #
5
+ # Usage:
6
+ # # config/initializers/fish0.rb
7
+ # Fish0::Configuration.configure do |config|
8
+ # config.mongo_hosts = ['localhost:27017']
9
+ # config.mongo_params = { database: 'your_data_development', read: { mode: :secondary } }
10
+ # end
11
+ ##
12
+ class Configuration
13
+ include ActiveSupport::Configurable
14
+
15
+ config_accessor :mongo_hosts do
16
+ ['localhost:27017']
17
+ end
18
+
19
+ ##
20
+ # Fish0::Configuration.mongo_params
21
+ #
22
+ # Usage:
23
+ # Enter your database and another params as second arguement to MongoClient::New
24
+ ##
25
+ config_accessor :mongo_params do
26
+ { database: 'fish0_development', read: { mode: :secondary } }
27
+ end
28
+ end
29
+ end
data/lib/fish0/engine.rb CHANGED
@@ -3,8 +3,8 @@ module Fish0
3
3
  isolate_namespace Fish0
4
4
 
5
5
  config.generators do |g|
6
- g.test_framework :rspec, :fixture => false
7
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
6
+ g.test_framework :rspec, fixture: false
7
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
8
8
  g.assets false
9
9
  g.helper false
10
10
  end
@@ -25,7 +25,7 @@ module Fish0
25
25
  end
26
26
 
27
27
  def all
28
- fetch.map(&to_entity)
28
+ Fish0::Collection.new(fetch.map(&to_entity))
29
29
  end
30
30
 
31
31
  def projection(values)
data/lib/fish0/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fish0
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
data/lib/fish0.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'mongo'
2
2
  require 'virtus'
3
3
  require 'fish0/version'
4
+ require 'fish0/configuration'
4
5
  require 'fish0/engine'
5
6
  require 'fish0/exceptions'
6
7
  require 'fish0/repository'
@@ -9,17 +10,23 @@ require 'fish0/concerns/cacheable'
9
10
  require 'fish0/concerns/paginatable'
10
11
  require 'fish0/concerns/view_model'
11
12
  require 'fish0/concerns/base'
13
+ require 'fish0/collection'
12
14
  require 'fish0/model'
13
15
 
14
16
  module Fish0
15
17
  class << self
16
18
  def mongo_reader
17
19
  Mongo::Logger.logger = mongo_config['logger'] || Rails.logger
18
- Mongo::Client.new(mongo_config['hosts'], mongo_config['params'])
20
+ Mongo::Client.new(mongo_config[:hosts], mongo_config[:params])
19
21
  end
20
22
 
21
23
  def mongo_config
22
- @mongo_config || Rails.application.config_for(:mongo)
24
+ if File.file?(File.expand_path('../config/mongo.yml', __FILE__))
25
+ config = Rails.application.config_for(:mongo)
26
+ Configuration.mongo_hosts = config['hosts']
27
+ Configuration.mongo_params = config['params']
28
+ end
29
+ @mongo_config || { hosts: Configuration.mongo_hosts, params: Configuration.mongo_params }
23
30
  end
24
31
  end
25
32
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fish0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Zuev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-10 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
@@ -98,30 +112,30 @@ dependencies:
98
112
  name: capybara
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '2.7'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '2.7'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: factory_girl_rails
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: '4.7'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: '4.7'
125
139
  description: |-
126
140
  Plugin for read-only content websites with MongoDB storage.
127
141
  Works perfect with Rambler&Co CQRS projects
@@ -135,10 +149,12 @@ files:
135
149
  - README.md
136
150
  - Rakefile
137
151
  - lib/fish0.rb
152
+ - lib/fish0/collection.rb
138
153
  - lib/fish0/concerns/base.rb
139
154
  - lib/fish0/concerns/cacheable.rb
140
155
  - lib/fish0/concerns/paginatable.rb
141
156
  - lib/fish0/concerns/view_model.rb
157
+ - lib/fish0/configuration.rb
142
158
  - lib/fish0/engine.rb
143
159
  - lib/fish0/exceptions.rb
144
160
  - lib/fish0/model.rb
@@ -189,7 +205,9 @@ homepage: https://github.com/rambler-digital-solutions/fish0
189
205
  licenses:
190
206
  - MIT
191
207
  metadata: {}
192
- post_install_message:
208
+ post_install_message: "\n WARNING if updating from version prior 0.0.6 you need to
209
+ change\n mongo configuration.\n Configure mongo using config/initializers/fish0.rb\n
210
+ \ Read examples in README.md\n "
193
211
  rdoc_options: []
194
212
  require_paths:
195
213
  - lib
@@ -250,3 +268,4 @@ test_files:
250
268
  - spec/dummy/README.rdoc
251
269
  - spec/models/model_spec.rb
252
270
  - spec/spec_helper.rb
271
+ has_rdoc: