Module: Appfuel::Application::AppContainer::ClassMethods
- Defined in:
- lib/appfuel/application/app_container.rb
Instance Method Summary collapse
- #app_container ⇒ Object
- #container_class_id ⇒ Object
-
#container_class_key(value = nil) ⇒ Object
Allow the concrete class that is using this mixing to change the key which would otherwise be the lowercase, underscored class name.
- #container_class_path ⇒ Object
- #container_class_type ⇒ Object
-
#container_feature_key ⇒ String
The feature name is the second item in the path, that is always prexfix with “features”.
-
#container_feature_name ⇒ String
The actual name of the feature.
-
#container_features_root_name ⇒ String
All root namespace for anything inside features, use this name.
- #container_global_name ⇒ String
-
#container_global_path? ⇒ Boolean
Determines if the container path represents a global glass.
- #container_key_basename ⇒ Object
-
#container_path ⇒ Array
An array representation of the application container namespace, where the root is the name of the application and not part of the namespace and the rest is hierarchical path to features or globals.
- #container_path=(list) ⇒ Array
-
#container_path? ⇒ Boolean
return [Boolean].
-
#container_qualified_key ⇒ String
Fully qualified key, meaning you can access the class this was mixed into if you stored it into the container using this key.
-
#container_relative_key ⇒ String
Container key relative from feature or global, depending on which class this is mixed into.
-
#container_root_name ⇒ Object
This is the application name used to identify the application container that is stored in the framework container.
-
#load_path_from_container_namespace(namespace) ⇒ Array
Parse the namespace assuming it is a dry container namespace and assign the list to container_path_list.
-
#load_path_from_ruby_namespace(namespace) ⇒ Array
Parse the namespace assuming it is a ruby namespace and assign the list to container_path_list.
-
#parse_list_string(namespace, char) ⇒ Array
An array of lower case snake cased strings.
-
#qualify_container_key(key, type_ns, opts = {}) ⇒ String
Convert the injection key to a fully qualified namespaced key that is used to pull an item out of the app container.
-
#top_container_key ⇒ String
This refers to either the global path or the path to a particular feature.
Instance Method Details
#app_container ⇒ Object
231 232 233 |
# File 'lib/appfuel/application/app_container.rb', line 231 def app_container Appfuel.app_container(container_root_name) end |
#container_class_id ⇒ Object
127 128 129 |
# File 'lib/appfuel/application/app_container.rb', line 127 def container_class_id container_class_key || container_key_basename end |
#container_class_key(value = nil) ⇒ Object
Allow the concrete class that is using this mixing to change the key which would otherwise be the lowercase, underscored class name
122 123 124 125 |
# File 'lib/appfuel/application/app_container.rb', line 122 def container_class_key(value = nil) return @container_class_key if value.nil? @container_class_key = value end |
#container_class_path ⇒ Object
135 136 137 |
# File 'lib/appfuel/application/app_container.rb', line 135 def container_class_path "#{top_container_key}.#{container_class_type}.#{container_class_id}" end |
#container_class_type ⇒ Object
131 132 133 |
# File 'lib/appfuel/application/app_container.rb', line 131 def container_class_type nil end |
#container_feature_key ⇒ String
The feature name is the second item in the path, that is always prexfix with “features”
92 93 94 95 96 |
# File 'lib/appfuel/application/app_container.rb', line 92 def container_feature_key @container_feature_key ||= ( "#{container_features_root_name}.#{container_feature_name}" ) end |
#container_feature_name ⇒ String
The actual name of the feature
84 85 86 |
# File 'lib/appfuel/application/app_container.rb', line 84 def container_feature_name container_path[1] end |
#container_features_root_name ⇒ String
All root namespace for anything inside features, use this name. It is important to note that to avoid long namespace in ruby features are the name of the module directly below the root.
76 77 78 |
# File 'lib/appfuel/application/app_container.rb', line 76 def container_features_root_name @container_features_root_name ||= 'features' end |
#container_global_name ⇒ String
157 158 159 |
# File 'lib/appfuel/application/app_container.rb', line 157 def container_global_name @container_global_name ||= 'global' end |
#container_global_path? ⇒ Boolean
Determines if the container path represents a global glass
152 153 154 |
# File 'lib/appfuel/application/app_container.rb', line 152 def container_global_path? container_path[1] == container_global_name end |
#container_key_basename ⇒ Object
114 115 116 |
# File 'lib/appfuel/application/app_container.rb', line 114 def container_key_basename @container_path.last end |
#container_path ⇒ Array
An array representation of the application container namespace, where the root is the name of the application and not part of the namespace and the rest is hierarchical path to features or globals
58 59 60 61 |
# File 'lib/appfuel/application/app_container.rb', line 58 def container_path load_path_from_ruby_namespace(self.to_s) unless container_path? @container_path end |
#container_path=(list) ⇒ Array
47 48 49 50 51 |
# File 'lib/appfuel/application/app_container.rb', line 47 def container_path=(list) fail "container path list must be an array" unless list.is_a?(Array) @container_path = list @container_path.freeze end |
#container_path? ⇒ Boolean
return [Boolean]
41 42 43 |
# File 'lib/appfuel/application/app_container.rb', line 41 def container_path? !@container_path.nil? end |
#container_qualified_key ⇒ String
Fully qualified key, meaning you can access the class this was mixed into if you stored it into the container using this key
143 144 145 146 147 |
# File 'lib/appfuel/application/app_container.rb', line 143 def container_qualified_key @container_qualified_key ||= ( "#{top_container_key}.#{container_relative_key}" ) end |
#container_relative_key ⇒ String
Container key relative from feature or global, depending on which class this is mixed into
102 103 104 |
# File 'lib/appfuel/application/app_container.rb', line 102 def container_relative_key @container_relative_key ||= container_path[2..-1].join('.') end |
#container_root_name ⇒ Object
This is the application name used to identify the application container that is stored in the framework container
67 68 69 |
# File 'lib/appfuel/application/app_container.rb', line 67 def container_root_name container_path.first end |
#load_path_from_container_namespace(namespace) ⇒ Array
Parse the namespace assuming it is a dry container namespace and assign the list to container_path_list
28 29 30 |
# File 'lib/appfuel/application/app_container.rb', line 28 def load_path_from_container_namespace(namespace) self.container_path = parse_list_string(namespace, '.') end |
#load_path_from_ruby_namespace(namespace) ⇒ Array
Parse the namespace assuming it is a ruby namespace and assign the list to container_path_list
19 20 21 |
# File 'lib/appfuel/application/app_container.rb', line 19 def load_path_from_ruby_namespace(namespace) self.container_path = parse_list_string(namespace, '::') end |
#parse_list_string(namespace, char) ⇒ Array
Returns an array of lower case snake cased strings.
35 36 37 38 |
# File 'lib/appfuel/application/app_container.rb', line 35 def parse_list_string(namespace, char) fail "split char must be '.' or '::'" unless ['.', '::'].include?(char) namespace.to_s.split(char).map {|i| i.underscore } end |
#qualify_container_key(key, type_ns, opts = {}) ⇒ String
Convert the injection key to a fully qualified namespaced key that is used to pull an item out of the app container.
Rules:
1) split the injection key by '.'
2) use the feature_key as the initial namespace
3) when the first part of the key is "global" use that instead of
the feature_key
4) append the type_key to the namespace unless it is "container"
type_key like "repositories" or "commands" removes the need for
the user to have to specify it since they already did that when
they used the type param.
note: feature_key in these examples will be "features.my-feature"
@example of a feature repository named foo
convert_to_qualified_container_key('foo', 'repositories')
returns 'features.my-feature.repositories.foo'
@example of a global command names bar
convert_to_qualified_container_key('global.bar', 'commands')
returns 'gloval.commands.bar'
@example of a container item baz
NOTE: feature container items are not in any namespace, they are any item
that can resolve from the namespace given by "feature_key"
convert_to_qualified_container_key('baz', 'container')
returns 'features.my-feature.baz'
@example of a global container item baz
NOTE: global container items are not in any namespace, they are any item
you can resolve from the application container.
convert_to_qualified_container_key('global.baz', 'container')
returns 'baz'
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/appfuel/application/app_container.rb', line 207 def qualify_container_key(key, type_ns, opts = {}) return key if opts[:no_context] == true parts = key.to_s.split('.') namespace = "#{container_feature_key}." if parts[0].downcase == 'global' namespace = 'global.' parts.shift elsif parts[0] == container_feature_name parts.shift end # when the key is a global container the namespace is only the path if type_ns == "container" namespace = '' if namespace == 'global.' type_ns = '' else type_ns = "#{type_ns}." end path = parts.join('.') "#{namespace}#{type_ns}#{path}" end |
#top_container_key ⇒ String
This refers to either the global path or the path to a particular feature
110 111 112 |
# File 'lib/appfuel/application/app_container.rb', line 110 def top_container_key container_global_path? ? container_global_name : container_feature_key end |