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) ⇒ 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
228 229 230 |
# File 'lib/appfuel/application/app_container.rb', line 228 def app_container Appfuel.app_container(container_root_name) end |
#container_class_id ⇒ Object
126 127 128 |
# File 'lib/appfuel/application/app_container.rb', line 126 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
121 122 123 124 |
# File 'lib/appfuel/application/app_container.rb', line 121 def container_class_key(value = nil) return @container_class_key if value.nil? @container_class_key = value end |
#container_class_path ⇒ Object
134 135 136 |
# File 'lib/appfuel/application/app_container.rb', line 134 def container_class_path "#{top_container_key}.#{container_class_type}.#{container_class_id}" end |
#container_class_type ⇒ Object
130 131 132 |
# File 'lib/appfuel/application/app_container.rb', line 130 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”
91 92 93 94 95 |
# File 'lib/appfuel/application/app_container.rb', line 91 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
83 84 85 |
# File 'lib/appfuel/application/app_container.rb', line 83 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.
75 76 77 |
# File 'lib/appfuel/application/app_container.rb', line 75 def container_features_root_name @container_features_root_name ||= 'features' end |
#container_global_name ⇒ String
156 157 158 |
# File 'lib/appfuel/application/app_container.rb', line 156 def container_global_name @container_global_name ||= 'global' end |
#container_global_path? ⇒ Boolean
Determines if the container path represents a global glass
151 152 153 |
# File 'lib/appfuel/application/app_container.rb', line 151 def container_global_path? container_path[1] == container_global_name end |
#container_key_basename ⇒ Object
113 114 115 |
# File 'lib/appfuel/application/app_container.rb', line 113 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
57 58 59 60 |
# File 'lib/appfuel/application/app_container.rb', line 57 def container_path load_path_from_ruby_namespace(self.to_s) unless container_path? @container_path end |
#container_path=(list) ⇒ Array
46 47 48 49 50 |
# File 'lib/appfuel/application/app_container.rb', line 46 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]
40 41 42 |
# File 'lib/appfuel/application/app_container.rb', line 40 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
142 143 144 145 146 |
# File 'lib/appfuel/application/app_container.rb', line 142 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
101 102 103 |
# File 'lib/appfuel/application/app_container.rb', line 101 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
66 67 68 |
# File 'lib/appfuel/application/app_container.rb', line 66 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
27 28 29 |
# File 'lib/appfuel/application/app_container.rb', line 27 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
18 19 20 |
# File 'lib/appfuel/application/app_container.rb', line 18 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.
34 35 36 37 |
# File 'lib/appfuel/application/app_container.rb', line 34 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) ⇒ 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
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'
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/appfuel/application/app_container.rb', line 206 def qualify_container_key(key, type_ns) 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
109 110 111 |
# File 'lib/appfuel/application/app_container.rb', line 109 def top_container_key container_global_path? ? container_global_name : container_feature_key end |