appfuel 0.2.3 → 0.2.4
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/CHANGELOG.md +15 -0
- data/README.md +78 -1
- data/appfuel.gemspec +1 -0
- data/docs/images/appfuel_basic_flow.png +0 -0
- data/lib/appfuel/application/app_container.rb +24 -1
- data/lib/appfuel/application/container_class_registration.rb +29 -4
- data/lib/appfuel/application/root.rb +1 -0
- data/lib/appfuel/application.rb +0 -1
- data/lib/appfuel/domain/base_criteria.rb +171 -0
- data/lib/appfuel/domain/criteria_builder.rb +248 -0
- data/lib/appfuel/domain/criteria_settings.rb +156 -0
- data/lib/appfuel/domain/dsl.rb +5 -1
- data/lib/appfuel/domain/entity.rb +1 -2
- data/lib/appfuel/domain/exists_criteria.rb +57 -0
- data/lib/appfuel/domain/expr.rb +66 -97
- data/lib/appfuel/domain/expr_conjunction.rb +27 -0
- data/lib/appfuel/domain/expr_parser.rb +199 -0
- data/lib/appfuel/domain/expr_transform.rb +68 -0
- data/lib/appfuel/domain/search_criteria.rb +137 -0
- data/lib/appfuel/domain.rb +6 -1
- data/lib/appfuel/feature/initializer.rb +5 -0
- data/lib/appfuel/handler/action.rb +3 -0
- data/lib/appfuel/handler/base.rb +11 -1
- data/lib/appfuel/handler/command.rb +4 -0
- data/lib/appfuel/repository/base.rb +16 -2
- data/lib/appfuel/repository/mapper.rb +41 -7
- data/lib/appfuel/repository/mapping_dsl.rb +4 -4
- data/lib/appfuel/repository/mapping_entry.rb +2 -2
- data/lib/appfuel/repository.rb +0 -1
- data/lib/appfuel/storage/db/active_record_model.rb +32 -28
- data/lib/appfuel/storage/db/mapper.rb +38 -125
- data/lib/appfuel/storage/db/repository.rb +6 -10
- data/lib/appfuel/storage/memory/repository.rb +4 -0
- data/lib/appfuel/types.rb +0 -1
- data/lib/appfuel/version.rb +1 -1
- data/lib/appfuel.rb +6 -10
- metadata +26 -7
- data/lib/appfuel/application/container_key.rb +0 -201
- data/lib/appfuel/application/qualify_container_key.rb +0 -76
- data/lib/appfuel/db_model.rb +0 -16
- data/lib/appfuel/domain/criteria.rb +0 -436
- data/lib/appfuel/repository/mapping_registry.rb +0 -121
@@ -2,37 +2,47 @@ module Appfuel
|
|
2
2
|
module Db
|
3
3
|
class Mapper < Appfuel::Repository::Mapper
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
# @param key [String, Symbol]
|
8
|
-
# @return [Boolean]
|
9
|
-
def entity_mapped?(name)
|
10
|
-
registry.entity?(name)
|
5
|
+
def search(domain_name, criteria, opts = {})
|
6
|
+
|
11
7
|
end
|
12
8
|
|
13
|
-
#
|
9
|
+
# Return qualified db column name from entity expression.
|
14
10
|
#
|
15
|
-
# @
|
16
|
-
# @
|
11
|
+
# @param expr [SpCore::Domain::Expr]
|
12
|
+
# @return db column name [String]
|
13
|
+
def qualified_db_column(expr, entry = nil)
|
14
|
+
table_name, column = db_table_column(expr, entry)
|
15
|
+
"#{table_name}.#{column}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Determine Domain Mapentry and DbModel from entity expression.
|
17
19
|
#
|
18
|
-
# @param
|
19
|
-
# @
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
db_class_key = entry.storage(:db)
|
20
|
+
# @param expr [SpCore::Domain::Expr]
|
21
|
+
# @return [table_name, column] [Array]
|
22
|
+
def db_table_column(expr, entry = nil)
|
23
|
+
entry ||= find(expr.domain_name, expr.domain_attr)
|
24
|
+
db = storage_class_from_entry(entry, :db)
|
24
25
|
|
25
|
-
|
26
|
+
[db.table_name, entry.storage_attr]
|
26
27
|
end
|
27
28
|
|
28
|
-
# Converts an entity expression into a valid active record expresion
|
29
|
-
#
|
29
|
+
# Converts an entity expression into a valid active record expresion
|
30
|
+
# expression.
|
30
31
|
#
|
31
32
|
# @param expr [Domain::Expr]
|
32
|
-
# @param
|
33
|
-
# @return [
|
34
|
-
|
35
|
-
|
33
|
+
# @param entry [Repository::MappingEntry] optional
|
34
|
+
# @return [Array] The first index is the expr string using ? for values
|
35
|
+
# The second index is the actual value(s)
|
36
|
+
def convert_expr(expr, entry = nil)
|
37
|
+
column = qualified_db_column(expr, entry)
|
38
|
+
op = expr.op
|
39
|
+
arg = case expr.op
|
40
|
+
when 'in', 'not in' then '(?)'
|
41
|
+
when 'between', 'not between' then '? AND ?'
|
42
|
+
else
|
43
|
+
'?'
|
44
|
+
end
|
45
|
+
["#{column} #{op} #{arg}", expr.value]
|
36
46
|
end
|
37
47
|
|
38
48
|
# Validates if a record exists in the table that matches the array with
|
@@ -40,14 +50,15 @@ module Appfuel
|
|
40
50
|
#
|
41
51
|
# @param criteria [Criteria]
|
42
52
|
# @return [Boolean]
|
43
|
-
def exists?(
|
44
|
-
domain_expr = criteria.exists_expr
|
53
|
+
def exists?(domain_expr)
|
45
54
|
domain_name = domain_expr.domain_name
|
46
55
|
domain_attr = domain_expr.domain_attr
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
|
57
|
+
entry = find(domain_name, domain_attr)
|
58
|
+
db_expr, values = convert_expr(domain_expr, entry)
|
59
|
+
db = storage_class_from_entry(entry, :db)
|
60
|
+
|
61
|
+
db.exists?([db_expr, values])
|
51
62
|
end
|
52
63
|
|
53
64
|
# Build a where expression from the mapped db class using the criteria.Ï
|
@@ -70,25 +81,6 @@ module Appfuel
|
|
70
81
|
relation
|
71
82
|
end
|
72
83
|
|
73
|
-
# Return qualified db column name from entity expression.
|
74
|
-
#
|
75
|
-
# @param expr [SpCore::Domain::Expr]
|
76
|
-
# @return db column name [String]
|
77
|
-
def qualified_db_column(expr)
|
78
|
-
table_name, column = db_table_column(expr)
|
79
|
-
"#{table_name}.#{column}"
|
80
|
-
end
|
81
|
-
|
82
|
-
# Determine Domain Mapentry and DbModel from entity expression.
|
83
|
-
#
|
84
|
-
# @param expr [SpCore::Domain::Expr]
|
85
|
-
# @return [table_name, column] [Array]
|
86
|
-
def db_table_column(expr)
|
87
|
-
entry = registry.find(expr.domain_name, expr.domain_attr)
|
88
|
-
db = registry.db_class_constant(entry.db_class)
|
89
|
-
[db.table_name, entry.db_column]
|
90
|
-
end
|
91
|
-
|
92
84
|
# Build an order by expression for the given db relation based on the
|
93
85
|
# criteria
|
94
86
|
#
|
@@ -129,85 +121,6 @@ module Appfuel
|
|
129
121
|
db_expr = create_db_expr(domain_expr)
|
130
122
|
relation.where([db_expr.string, db_expr.values])
|
131
123
|
end
|
132
|
-
|
133
|
-
# Convert the entity into a hash of db tables that represent
|
134
|
-
# that entity. Each table has its own hash of mapped columns.
|
135
|
-
#
|
136
|
-
# @param domain [Appfuel::Domain::Entity]
|
137
|
-
# @param opts [Hash]
|
138
|
-
# @option exclued [Array] list of columns to exclude from mapping
|
139
|
-
#
|
140
|
-
# @return [Hash] each key is a table with a hash of column name/value
|
141
|
-
def to_storage(domain, opts = {})
|
142
|
-
excluded = opts[:exclude] || []
|
143
|
-
data = {}
|
144
|
-
each_entity_attr(domain.domain_name) do |entry|
|
145
|
-
column = entry.storage_attr
|
146
|
-
db_class = entry.storage(:db)
|
147
|
-
next if excluded.include?(column) || entry.skip?
|
148
|
-
|
149
|
-
data[db_class] = {} unless data.key?(db_class)
|
150
|
-
data[db_class][column] = entity_value(domain, entry)
|
151
|
-
end
|
152
|
-
data
|
153
|
-
end
|
154
|
-
|
155
|
-
# Handles entity value by checking if its a computed property,
|
156
|
-
# fetching the value and converting undefined values to nil.
|
157
|
-
#
|
158
|
-
# @param domain [Appfuel::Domain::Entity]
|
159
|
-
# @param map_entry [MappingEntity]
|
160
|
-
# @return the value
|
161
|
-
def entity_value(domain, entry)
|
162
|
-
value = retrieve_entity_value(domain, entry.domain_attr)
|
163
|
-
if entry.computed_attr?
|
164
|
-
value = entry.compute_attr(value)
|
165
|
-
end
|
166
|
-
|
167
|
-
value = nil if undefined?(value)
|
168
|
-
|
169
|
-
value
|
170
|
-
end
|
171
|
-
|
172
|
-
# @params value [mixed]
|
173
|
-
# @return [Boolean]
|
174
|
-
def undefined?(value)
|
175
|
-
value == Types::Undefined
|
176
|
-
end
|
177
|
-
|
178
|
-
# Fetch the value for the entity attribute. When the attribute name
|
179
|
-
# contains a '.' then traverse the dots and call the last attribute
|
180
|
-
# for the value
|
181
|
-
#
|
182
|
-
# @param domain [Appfuel::Domain::Entity]
|
183
|
-
# @param entity_attribute [String]
|
184
|
-
# @return the value
|
185
|
-
def retrieve_entity_value(domain, entity_attr)
|
186
|
-
chain = entity_attr.split('.')
|
187
|
-
target = domain
|
188
|
-
chain.each do |attr_method|
|
189
|
-
unless target.respond_to?(attr_method)
|
190
|
-
return nil
|
191
|
-
end
|
192
|
-
|
193
|
-
target = target.public_send(attr_method)
|
194
|
-
end
|
195
|
-
target
|
196
|
-
end
|
197
|
-
|
198
|
-
# Create nested hashes from string
|
199
|
-
#
|
200
|
-
# @param domain_attr [String]
|
201
|
-
# @param entity_value [String]
|
202
|
-
# @return [nested hash]
|
203
|
-
def create_entity_hash(domain_attr, entity_value)
|
204
|
-
domain_attr.split('.').reverse.inject(entity_value) { |a,n| {n => a}}
|
205
|
-
end
|
206
|
-
|
207
|
-
def model_attributes(relation)
|
208
|
-
ap relation
|
209
|
-
relation.attributes.select {|_, value| !value.nil?}
|
210
|
-
end
|
211
124
|
end
|
212
125
|
end
|
213
126
|
end
|
@@ -2,8 +2,12 @@ module Appfuel
|
|
2
2
|
module Db
|
3
3
|
class Repository < Appfuel::Repository::Base
|
4
4
|
class << self
|
5
|
+
def container_class_type
|
6
|
+
"#{super}.db"
|
7
|
+
end
|
8
|
+
|
5
9
|
def create_mapper(maps = nil)
|
6
|
-
Mapper.new(maps)
|
10
|
+
Mapper.new(container_root_name, maps)
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -116,14 +120,6 @@ module Appfuel
|
|
116
120
|
apply_query_conditions(criteria, relation)
|
117
121
|
end
|
118
122
|
|
119
|
-
# Factory method to create a pagination result
|
120
|
-
#
|
121
|
-
# @param data [Hash]
|
122
|
-
# @return [SpCore::Pagination::Result]
|
123
|
-
def create_pager_result(data)
|
124
|
-
Appfuel::Pagination::Result.new(data)
|
125
|
-
end
|
126
|
-
|
127
123
|
# Factory method to create a domain entity
|
128
124
|
#
|
129
125
|
# @param domain_name [String]
|
@@ -197,7 +193,7 @@ module Appfuel
|
|
197
193
|
#
|
198
194
|
# @param criteria [SpCore::Criteria]
|
199
195
|
# @return [SpCore::Domain::Entity, SpCore::Domain::EntityCollection]
|
200
|
-
def
|
196
|
+
def search(criteria)
|
201
197
|
return execute_criteria(criteria) if criteria.exec?
|
202
198
|
|
203
199
|
begin
|
data/lib/appfuel/types.rb
CHANGED
data/lib/appfuel/version.rb
CHANGED
data/lib/appfuel.rb
CHANGED
@@ -29,16 +29,6 @@ require "appfuel/validation"
|
|
29
29
|
# Dependency management for actions, commands and repos
|
30
30
|
require "appfuel/root_module"
|
31
31
|
|
32
|
-
require "appfuel/presenter"
|
33
|
-
|
34
|
-
require "appfuel/repository"
|
35
|
-
require "appfuel/db_model"
|
36
|
-
require "appfuel/repository_runner"
|
37
|
-
require "appfuel/storage"
|
38
|
-
|
39
|
-
# callable operations
|
40
|
-
require "appfuel/handler"
|
41
|
-
|
42
32
|
module Appfuel
|
43
33
|
# The appfuel top level interface mainly deals with interacting with both
|
44
34
|
# the application dependency injection container and the framework di
|
@@ -206,5 +196,11 @@ end
|
|
206
196
|
|
207
197
|
# Domain Entities
|
208
198
|
require "appfuel/domain"
|
199
|
+
require "appfuel/presenter"
|
200
|
+
require "appfuel/repository"
|
201
|
+
require "appfuel/repository_runner"
|
202
|
+
require "appfuel/storage"
|
203
|
+
require "appfuel/handler"
|
204
|
+
|
209
205
|
|
210
206
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appfuel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Scott-Buccleuch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: parslet
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.8.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.8.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -232,6 +246,7 @@ files:
|
|
232
246
|
- ".rspec"
|
233
247
|
- ".rubocop.yml"
|
234
248
|
- ".travis.yml"
|
249
|
+
- CHANGELOG.md
|
235
250
|
- CODE_OF_CONDUCT.md
|
236
251
|
- Gemfile
|
237
252
|
- README.md
|
@@ -239,12 +254,11 @@ files:
|
|
239
254
|
- appfuel.gemspec
|
240
255
|
- bin/console
|
241
256
|
- bin/setup
|
257
|
+
- docs/images/appfuel_basic_flow.png
|
242
258
|
- lib/appfuel.rb
|
243
259
|
- lib/appfuel/application.rb
|
244
260
|
- lib/appfuel/application/app_container.rb
|
245
261
|
- lib/appfuel/application/container_class_registration.rb
|
246
|
-
- lib/appfuel/application/container_key.rb
|
247
|
-
- lib/appfuel/application/qualify_container_key.rb
|
248
262
|
- lib/appfuel/application/root.rb
|
249
263
|
- lib/appfuel/cli_msg_request.rb
|
250
264
|
- lib/appfuel/configuration.rb
|
@@ -252,14 +266,20 @@ files:
|
|
252
266
|
- lib/appfuel/configuration/file_loader.rb
|
253
267
|
- lib/appfuel/configuration/populate.rb
|
254
268
|
- lib/appfuel/configuration/search.rb
|
255
|
-
- lib/appfuel/db_model.rb
|
256
269
|
- lib/appfuel/domain.rb
|
257
|
-
- lib/appfuel/domain/
|
270
|
+
- lib/appfuel/domain/base_criteria.rb
|
271
|
+
- lib/appfuel/domain/criteria_builder.rb
|
272
|
+
- lib/appfuel/domain/criteria_settings.rb
|
258
273
|
- lib/appfuel/domain/domain_name_parser.rb
|
259
274
|
- lib/appfuel/domain/dsl.rb
|
260
275
|
- lib/appfuel/domain/entity.rb
|
261
276
|
- lib/appfuel/domain/entity_collection.rb
|
277
|
+
- lib/appfuel/domain/exists_criteria.rb
|
262
278
|
- lib/appfuel/domain/expr.rb
|
279
|
+
- lib/appfuel/domain/expr_conjunction.rb
|
280
|
+
- lib/appfuel/domain/expr_parser.rb
|
281
|
+
- lib/appfuel/domain/expr_transform.rb
|
282
|
+
- lib/appfuel/domain/search_criteria.rb
|
263
283
|
- lib/appfuel/domain/value_object.rb
|
264
284
|
- lib/appfuel/errors.rb
|
265
285
|
- lib/appfuel/feature.rb
|
@@ -283,7 +303,6 @@ files:
|
|
283
303
|
- lib/appfuel/repository/mapper.rb
|
284
304
|
- lib/appfuel/repository/mapping_dsl.rb
|
285
305
|
- lib/appfuel/repository/mapping_entry.rb
|
286
|
-
- lib/appfuel/repository/mapping_registry.rb
|
287
306
|
- lib/appfuel/repository_runner.rb
|
288
307
|
- lib/appfuel/request.rb
|
289
308
|
- lib/appfuel/response.rb
|
@@ -1,201 +0,0 @@
|
|
1
|
-
module Appfuel
|
2
|
-
module Application
|
3
|
-
# Mixins to allow you to handle application container keys. The application
|
4
|
-
# container operates based on certain conventions which we take into account
|
5
|
-
# here.
|
6
|
-
module ContainerKey
|
7
|
-
# Parse the namespace assuming it is a ruby namespace and assign
|
8
|
-
# the list to container_path_list
|
9
|
-
#
|
10
|
-
# @param namespace [String]
|
11
|
-
# @return [Array]
|
12
|
-
def load_path_from_ruby_namespace(namespace)
|
13
|
-
self.container_path = parse_list_string(namespace, '::')
|
14
|
-
end
|
15
|
-
|
16
|
-
# Parse the namespace assuming it is a dry container namespace and
|
17
|
-
# assign the list to container_path_list
|
18
|
-
#
|
19
|
-
# @param namespace [String]
|
20
|
-
# @return [Array]
|
21
|
-
def load_path_from_container_namespace(namespace)
|
22
|
-
self.container_path = parse_list_string(namespace, '.')
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param namespace [String] encoded string that represents a path
|
26
|
-
# @param char [String] character used to split the keys into a list
|
27
|
-
# @return [Array] an array of lower case snake cased strings
|
28
|
-
def parse_list_string(namespace, char)
|
29
|
-
fail "split char must be '.' or '::'" unless ['.', '::'].include?(char)
|
30
|
-
namespace.to_s.split(char).map {|i| i.underscore }
|
31
|
-
end
|
32
|
-
|
33
|
-
# return [Boolean]
|
34
|
-
def container_path?
|
35
|
-
!@container_path.nil?
|
36
|
-
end
|
37
|
-
|
38
|
-
# @param list [Array] list of container namespace parts including root
|
39
|
-
# @return [Array]
|
40
|
-
def container_path=(list)
|
41
|
-
fail "container path list must be an array" unless list.is_a?(Array)
|
42
|
-
@container_path = list
|
43
|
-
@container_path.freeze
|
44
|
-
end
|
45
|
-
|
46
|
-
# An array representation of the application container namespace, where
|
47
|
-
# the root is the name of the application and not part of the namespace
|
48
|
-
# and the rest is hierarchical path to features or globals
|
49
|
-
#
|
50
|
-
# @return [Array]
|
51
|
-
def container_path
|
52
|
-
load_path_from_ruby_namespace(self.to_s) unless container_path?
|
53
|
-
@container_path
|
54
|
-
end
|
55
|
-
|
56
|
-
# This is the application name used to identify the application container
|
57
|
-
# that is stored in the framework container
|
58
|
-
#
|
59
|
-
# @return string
|
60
|
-
def container_root_name
|
61
|
-
@container_root_name ||= container_path.first
|
62
|
-
end
|
63
|
-
|
64
|
-
# All root namespace for anything inside features, use this name. It is
|
65
|
-
# important to note that to avoid long namespace in ruby features are the
|
66
|
-
# name of the module directly below the root.
|
67
|
-
#
|
68
|
-
# @return [String]
|
69
|
-
def container_features_root_name
|
70
|
-
@container_features_root_name ||= 'features'
|
71
|
-
end
|
72
|
-
|
73
|
-
# The actual name of the feature
|
74
|
-
#
|
75
|
-
# @return [String]
|
76
|
-
def container_feature_name
|
77
|
-
container_path[1]
|
78
|
-
end
|
79
|
-
|
80
|
-
# The feature name is the second item in the path, that is always prexfix
|
81
|
-
# with "features"
|
82
|
-
#
|
83
|
-
# @return [String]
|
84
|
-
def container_feature_key
|
85
|
-
@container_feature_key ||= (
|
86
|
-
"#{container_features_root_name}.#{container_feature_name}"
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Container key relative from feature or global, depending on which class
|
91
|
-
# this is mixed into
|
92
|
-
#
|
93
|
-
# @return [String]
|
94
|
-
def container_relative_key
|
95
|
-
@container_relative_key ||= container_path[2..-1].join('.')
|
96
|
-
end
|
97
|
-
|
98
|
-
# This refers to either the global path or the path to a particular
|
99
|
-
# feature
|
100
|
-
#
|
101
|
-
# @return [String]
|
102
|
-
def top_container_key
|
103
|
-
container_global_path? ? container_global_name : container_feature_key
|
104
|
-
end
|
105
|
-
|
106
|
-
def container_key_basename
|
107
|
-
@container_path.last
|
108
|
-
end
|
109
|
-
|
110
|
-
# Fully qualified key, meaning you can access the class this was mixed into
|
111
|
-
# if you stored it into the container using this key
|
112
|
-
#
|
113
|
-
# @return [String]
|
114
|
-
def container_qualified_key
|
115
|
-
@container_qualified_key ||= (
|
116
|
-
"#{top_container_key}.#{container_relative_key}"
|
117
|
-
)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Determines if the container path represents a global glass
|
121
|
-
#
|
122
|
-
# @return [Boolean]
|
123
|
-
def container_global_path?
|
124
|
-
container_path[1] == container_global_name
|
125
|
-
end
|
126
|
-
|
127
|
-
# @return [String]
|
128
|
-
def container_global_name
|
129
|
-
@container_global_name ||= 'global'
|
130
|
-
end
|
131
|
-
|
132
|
-
# Convert the injection key to a fully qualified namespaced key that
|
133
|
-
# is used to pull an item out of the app container.
|
134
|
-
#
|
135
|
-
# Rules:
|
136
|
-
# 1) split the injection key by '.'
|
137
|
-
# 2) use the feature_key as the initial namespace
|
138
|
-
# 3) when the first part of the key is "global" use that instead of
|
139
|
-
# the feature_key
|
140
|
-
# 4) append the type_key to the namespace unless it is "container"
|
141
|
-
# type_key like "repositories" or "commands" removes the need for
|
142
|
-
# the user to have to specify it since they already did that when
|
143
|
-
# they used the type param.
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# note: feature_key in these examples will be "features.my-feature"
|
147
|
-
# @example of a feature repository named foo
|
148
|
-
#
|
149
|
-
# convert_to_qualified_container_key('foo', 'repositories')
|
150
|
-
#
|
151
|
-
# returns 'features.my-feature.repositories.foo'
|
152
|
-
#
|
153
|
-
# @example of a global command names bar
|
154
|
-
#
|
155
|
-
# convert_to_qualified_container_key('global.bar', 'commands')
|
156
|
-
#
|
157
|
-
# returns 'gloval.commands.bar'
|
158
|
-
#
|
159
|
-
# @example of a container item baz
|
160
|
-
# NOTE: feature container items are not in any namespace, they are any item
|
161
|
-
# that can resolve from the namespace given by "feature_key"
|
162
|
-
#
|
163
|
-
# convert_to_qualified_container_key('baz', 'container')
|
164
|
-
#
|
165
|
-
# returns 'features.my-feature.baz'
|
166
|
-
#
|
167
|
-
# @example of a global container item baz
|
168
|
-
# NOTE: global container items are not in any namespace, they are any item
|
169
|
-
# you can resolve from the application container.
|
170
|
-
#
|
171
|
-
# convert_to_qualified_container_key('global.baz', 'container')
|
172
|
-
#
|
173
|
-
# returns 'baz'
|
174
|
-
#
|
175
|
-
# @param key [String] partial key to be built into fully qualified key
|
176
|
-
# @param type_ns [String] namespace for key
|
177
|
-
# @return [String] fully qualified namespaced key
|
178
|
-
def qualify_container_key(key, type_ns)
|
179
|
-
parts = key.to_s.split('.')
|
180
|
-
namespace = "#{container_feature_key}."
|
181
|
-
if parts[0].downcase == 'global'
|
182
|
-
namespace = 'global.'
|
183
|
-
parts.shift
|
184
|
-
elsif parts[0] == container_feature_name
|
185
|
-
parts.shift
|
186
|
-
end
|
187
|
-
|
188
|
-
# when the key is a global container the namespace is only the path
|
189
|
-
if type_ns == "container"
|
190
|
-
namespace = '' if namespace == 'global.'
|
191
|
-
type_ns = ''
|
192
|
-
else
|
193
|
-
type_ns = "#{type_ns}."
|
194
|
-
end
|
195
|
-
|
196
|
-
path = parts.join('.')
|
197
|
-
"#{namespace}#{type_ns}#{path}"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module Appfuel
|
2
|
-
module Application
|
3
|
-
# Mixins to allow you to handle application container keys. The application
|
4
|
-
# container operates based on certain conventions which we take into account
|
5
|
-
# here.
|
6
|
-
module QualifyContainerKey
|
7
|
-
# Convert the injection key to a fully qualified namespaced key that
|
8
|
-
# is used to pull an item out of the app container.
|
9
|
-
#
|
10
|
-
# Rules:
|
11
|
-
# 1) split the injection key by '.'
|
12
|
-
# 2) use the feature_key as the initial namespace
|
13
|
-
# 3) when the first part of the key is "global" use that instead of
|
14
|
-
# the feature_key
|
15
|
-
# 4) append the type_key to the namespace unless it is "container"
|
16
|
-
# type_key like "repositories" or "commands" removes the need for
|
17
|
-
# the user to have to specify it since they already did that when
|
18
|
-
# they used the type param.
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# note: feature_key in these examples will be "features.my-feature"
|
22
|
-
# @example of a feature repository named foo
|
23
|
-
#
|
24
|
-
# convert_to_qualified_container_key('foo', 'repositories')
|
25
|
-
#
|
26
|
-
# returns 'features.my-feature.repositories.foo'
|
27
|
-
#
|
28
|
-
# @example of a global command names bar
|
29
|
-
#
|
30
|
-
# convert_to_qualified_container_key('global.bar', 'commands')
|
31
|
-
#
|
32
|
-
# returns 'gloval.commands.bar'
|
33
|
-
#
|
34
|
-
# @example of a container item baz
|
35
|
-
# NOTE: feature container items are not in any namespace, they are any item
|
36
|
-
# that can resolve from the namespace given by "feature_key"
|
37
|
-
#
|
38
|
-
# convert_to_qualified_container_key('baz', 'container')
|
39
|
-
#
|
40
|
-
# returns 'features.my-feature.baz'
|
41
|
-
#
|
42
|
-
# @example of a global container item baz
|
43
|
-
# NOTE: global container items are not in any namespace, they are any item
|
44
|
-
# you can resolve from the application container.
|
45
|
-
#
|
46
|
-
# convert_to_qualified_container_key('global.baz', 'container')
|
47
|
-
#
|
48
|
-
# returns 'baz'
|
49
|
-
#
|
50
|
-
# @param key [String] partial key to be built into fully qualified key
|
51
|
-
# @param type_ns [String] namespace for key
|
52
|
-
# @return [String] fully qualified namespaced key
|
53
|
-
def qualify_container_key(key, type_ns)
|
54
|
-
parts = key.to_s.split('.')
|
55
|
-
namespace = "#{container_feature_key}."
|
56
|
-
if parts[0].downcase == 'global'
|
57
|
-
namespace = 'global.'
|
58
|
-
parts.shift
|
59
|
-
elsif parts[0] == container_feature_name
|
60
|
-
parts.shift
|
61
|
-
end
|
62
|
-
|
63
|
-
# when the key is a global container the namespace is only the path
|
64
|
-
if type_ns == "container"
|
65
|
-
namespace = '' if namespace == 'global.'
|
66
|
-
type_ns = ''
|
67
|
-
else
|
68
|
-
type_ns = "#{type_ns}."
|
69
|
-
end
|
70
|
-
|
71
|
-
path = parts.join('.')
|
72
|
-
"#{namespace}#{type_ns}#{path}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/appfuel/db_model.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Appfuel
|
2
|
-
class DbModel < ActiveRecord::Base
|
3
|
-
self.abstract_class = true
|
4
|
-
extend Appfuel::Application::ContainerKey
|
5
|
-
extend Appfuel::Application::ContainerClassRegistration
|
6
|
-
|
7
|
-
def self.inherited(klass)
|
8
|
-
super
|
9
|
-
register_container_class(klass)
|
10
|
-
end
|
11
|
-
|
12
|
-
def entity_attributes
|
13
|
-
attributes.symbolize_keys.select {|_,value| !value.nil?}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|