Module: Appfuel::Application::AppContainer::ClassMethods

Defined in:
lib/appfuel/application/app_container.rb

Instance Method Summary collapse

Instance Method Details

#app_containerObject



228
229
230
# File 'lib/appfuel/application/app_container.rb', line 228

def app_container
  Appfuel.app_container(container_root_name)
end

#container_class_idObject



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

Returns:

  • nil



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_pathObject



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_typeObject



130
131
132
# File 'lib/appfuel/application/app_container.rb', line 130

def container_class_type
  nil
end

#container_feature_keyString

The feature name is the second item in the path, that is always prexfix with “features”

Returns:

  • (String)


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_nameString

The actual name of the feature

Returns:

  • (String)


83
84
85
# File 'lib/appfuel/application/app_container.rb', line 83

def container_feature_name
  container_path[1]
end

#container_features_root_nameString

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.

Returns:

  • (String)


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_nameString

Returns:

  • (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

Returns:

  • (Boolean)


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_basenameObject



113
114
115
# File 'lib/appfuel/application/app_container.rb', line 113

def container_key_basename
  @container_path.last
end

#container_pathArray

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

Returns:

  • (Array)


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

Parameters:

  • list (Array)

    list of container namespace parts including root

Returns:

  • (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]

Returns:

  • (Boolean)


40
41
42
# File 'lib/appfuel/application/app_container.rb', line 40

def container_path?
  !@container_path.nil?
end

#container_qualified_keyString

Fully qualified key, meaning you can access the class this was mixed into if you stored it into the container using this key

Returns:

  • (String)


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_keyString

Container key relative from feature or global, depending on which class this is mixed into

Returns:

  • (String)


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_nameObject

This is the application name used to identify the application container that is stored in the framework container

Returns:

  • string



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

Parameters:

  • namespace (String)

Returns:

  • (Array)


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

Parameters:

  • namespace (String)

Returns:

  • (Array)


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.

Parameters:

  • namespace (String)

    encoded string that represents a path

  • char (String)

    character used to split the keys into a list

Returns:

  • (Array)

    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 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'

Parameters:

  • key (String)

    partial key to be built into fully qualified key

  • type_ns (String)

    namespace for key

Returns:

  • (String)

    fully qualified namespaced key



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_keyString

This refers to either the global path or the path to a particular feature

Returns:

  • (String)


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