Class: Jets::Configuration::Generators

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/configuration.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerators

Returns a new instance of Generators.



106
107
108
109
110
111
112
113
114
115
# File 'lib/jets/configuration.rb', line 106

def initialize
  @aliases = Hash.new { |h, k| h[k] = {} }
  @options = Hash.new { |h, k| h[k] = {} }
  @fallbacks = {}
  @templates = []
  @colorize_logging = true
  @api_only = false
  @hidden_namespaces = []
  @after_generate_callbacks = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/jets/configuration.rb', line 132

def method_missing(method, *args)
  method = method.to_s.delete_suffix("=").to_sym

  # Note: Using :rails because piggybacking off of rails generators
  if args.empty?
    if method == :rails
      return @options[method]
    else
      return @options[:rails][method]
    end
  end

  if method == :rails || args.first.is_a?(Hash)
    namespace, configuration = method, args.shift
  else
    # Examples:
    #   method :orm args [:active_record, {:migration=>true, :timestamps=>true}] @options {}
    #   namespace :active_record
    #   configuration {:migration=>true, :timestamps=>true}
    namespace, configuration = args.shift, args.shift
    namespace = namespace.to_sym if namespace.respond_to?(:to_sym)
    @options[:rails][method] = namespace
  end

  if configuration
    aliases = configuration.delete(:aliases)
    @aliases[namespace].merge!(aliases) if aliases
    @options[namespace].merge!(configuration)
  end

  # Example @options: {:rails=>{:orm=>:active_record}, :active_record=>{:migration=>true, :timestamps=>true}}
end

Instance Attribute Details

#after_generate_callbacksObject (readonly)

Returns the value of attribute after_generate_callbacks.



104
105
106
# File 'lib/jets/configuration.rb', line 104

def after_generate_callbacks
  @after_generate_callbacks
end

#aliasesObject

Returns the value of attribute aliases.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def aliases
  @aliases
end

#api_onlyObject

Returns the value of attribute api_only.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def api_only
  @api_only
end

#colorize_loggingObject

Returns the value of attribute colorize_logging.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def colorize_logging
  @colorize_logging
end

#fallbacksObject

Returns the value of attribute fallbacks.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def fallbacks
  @fallbacks
end

#hidden_namespacesObject (readonly)

Returns the value of attribute hidden_namespaces.



104
105
106
# File 'lib/jets/configuration.rb', line 104

def hidden_namespaces
  @hidden_namespaces
end

#optionsObject

Returns the value of attribute options.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def options
  @options
end

#templatesObject

Returns the value of attribute templates.



103
104
105
# File 'lib/jets/configuration.rb', line 103

def templates
  @templates
end

Instance Method Details

#after_generate(&block) ⇒ Object



128
129
130
# File 'lib/jets/configuration.rb', line 128

def after_generate(&block)
  @after_generate_callbacks << block
end

#hide_namespace(namespace) ⇒ Object



124
125
126
# File 'lib/jets/configuration.rb', line 124

def hide_namespace(namespace)
  @hidden_namespaces << namespace
end

#initialize_copy(source) ⇒ Object



117
118
119
120
121
122
# File 'lib/jets/configuration.rb', line 117

def initialize_copy(source)
  @aliases = @aliases.deep_dup
  @options = @options.deep_dup
  @fallbacks = @fallbacks.deep_dup
  @templates = @templates.dup
end