tzispa_data 0.2.1 → 0.3.0

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: 541b8583385fa3cd067dcd15d4600da2f0be5b55
4
- data.tar.gz: f8ecf752ae8345dc0267975a73b644265053e8e5
3
+ metadata.gz: d93f8550dc521d79171ed9b7a38ea5b3cd130260
4
+ data.tar.gz: f984c6b25aa8f4dd2b6bc663a5099e98eaac68ef
5
5
  SHA512:
6
- metadata.gz: 26e9037dd1d200fc2eaef19561dc355e8cb193f2c915ed001fc11b8886bff12987bf6f6c50aaeeba55ffbb4cf2b9ffc975bb6eda95b6d8c15e20e3d3fe6892a0
7
- data.tar.gz: edca3ff381626055bbff6b841e0b0355b5b1c42fc5013e33bacd371d25b82f0a432dc64df7d954644e44dc3480a990c2ee9907cc8717c14ce50129aec1dcfb60
6
+ metadata.gz: 4ef78463937d73e27ddf3cfa42546d243f4833e572161c52c437867517ec128720451570aa1336f821ca3178cb5898a8ad24ecb277ae0bd2fd75e82003755def
7
+ data.tar.gz: af14bd698ae4086476728169758bc7a4627e4bbe488deced716c3adcfea43f3376446bd59f342c3457ac20251bcbf7e7560a52a95e1ea0dfaa5df8ed5f745587
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  Tzispa Data
2
2
 
3
+ ## v0.3.0
4
+ - local repository helpers preloading
5
+ - fix local repository loader
6
+ - repositories module namespace get & simplifification
7
+
3
8
  ## v0.2.1
4
9
  - code fixes for replacing TzString with String refinement
5
10
 
@@ -29,21 +29,34 @@ module Tzispa
29
29
 
30
30
  def [](model, repo_id=nil)
31
31
  selected_repo = repo_id || @adapters.default
32
- raise UnknownModel.new("The '#{model}' model does not exists in the adapter '#{selected_repo}'") unless @pool.has_key? self.class.key(model, selected_repo)
33
- @pool[self.class.key(model.to_sym, selected_repo)]
32
+ raise UnknownModel.new("The '#{model}' model does not exists in the adapter '#{selected_repo}'") unless @pool.has_key?(selected_repo) && @pool[selected_repo].has_key?(model.to_sym)
33
+ @pool[selected_repo][model.to_sym]
34
34
  end
35
35
 
36
- def load!
36
+ def models(repo_id=nil)
37
+ @pool[repo_id || @adapters.default].values
38
+ end
39
+
40
+ def module_const(repo_id=nil)
41
+ selected_repo = repo_id || @adapters.default
42
+ @pool[selected_repo][:'__repository_module'] ||= repository_module(selected_repo)
43
+ end
44
+
45
+ def load!(domain)
37
46
  @config.each { |id, cfg|
38
47
  Mutex.new.synchronize {
48
+ @pool[id] = Hash.new
39
49
  Sequel::Model.db = @adapters[id]
40
50
  if cfg.local
41
- build_local_repo id, cfg
51
+ load_local_helpers id, cfg
52
+ load_local_models id, cfg
42
53
  else
43
54
  require cfg.gem
44
- self.class.include "Repository::#{id.to_s.camelize}".constantize
55
+ repo_module = "#{id.to_s.camelize}".constantize
56
+ self.class.include repo_module
45
57
  self.class.send "load_#{id}", self, id, cfg
46
58
  end
59
+ domain.include module_const(id)
47
60
  }
48
61
  }
49
62
  self
@@ -54,26 +67,34 @@ module Tzispa
54
67
  config.extensions.split(',').each { |ext|
55
68
  model_class.db.extension ext.to_sym
56
69
  } if config.respond_to? :extensions
57
- @pool[self.class.key(model_id, repo_id)] = model_class
70
+ @pool[repo_id][model_id.to_sym] = model_class
58
71
  end
59
72
 
60
73
  private
61
74
 
62
- def build_local_repo(repo_id, config)
63
- Dir["./#{root.to_s.downcase}/#{repo_id}/*.rb"].each { |file|
75
+ def repository_module(repo_id)
76
+ rm = @pool[repo_id].first[1].name.split('::')
77
+ rm.pop
78
+ rm.join('::').constantize
79
+ end
80
+
81
+ def load_local_models(repo_id, config)
82
+ models_path = "./#{root}/#{repo_id}/model"
83
+ repo_module = "#{repo_id.to_s.camelize}::Model".constantize
84
+ Dir["#{models_path}/*.rb"].each { |file|
64
85
  model_id = file.split('/').last.split('.').first
65
- require local_model_source(model_id, repo_id)
66
- model_class = "Repository::#{repo_id.camelize}::#{model_id.camelize}".constantize
86
+ require "#{models_path}/#{model_id}"
87
+ model_class = "#{repo_module}::#{model_id.camelize}".constantize
67
88
  register model_id, model_class, repo_id, config
68
89
  }
69
90
  end
70
91
 
71
- def local_model_source(model, repo_id)
72
- "./#{root.to_s.downcase}/#{repo_id}/#{model}"
73
- end
74
-
75
- def self.key(model_id, repo_id)
76
- "#{model_id}@#{repo_id}".to_sym
92
+ def load_local_helpers(repo_id, config)
93
+ helpers_path = "./#{root}/#{repo_id}/helpers"
94
+ Dir["#{helpers_path}/*.rb"].each { |file|
95
+ helper_id = file.split('/').last.split('.').first
96
+ require "#{helpers_path}/#{helper_id}"
97
+ }
77
98
  end
78
99
 
79
100
  end
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Data
5
5
 
6
- VERSION = '0.2.1'
6
+ VERSION = '0.3.0'
7
7
  NAME = 'Tzispa Data'
8
8
  GEM_NAME = 'tzispa_data'
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
40
+ version: '0.3'
41
41
  description: Data access layer for Tzispa
42
42
  email:
43
43
  - japinero@area-integral.com
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.5.2
78
+ rubygems_version: 2.6.10
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Data access for Tzispa framework