Class: Stax::Generators::DynamoGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/dynamo/dynamo_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def attributes
  @attributes
end

#hashObject

Returns the value of attribute hash.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def hash
  @hash
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def id
  @id
end

#rangeObject

Returns the value of attribute range.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def range
  @range
end

#stackObject

Returns the value of attribute stack.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def stack
  @stack
end

#tableObject

Returns the value of attribute table.



10
11
12
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10

def table
  @table
end

Instance Method Details

#add_to_staxfileObject



37
38
39
# File 'lib/generators/dynamo/dynamo_generator.rb', line 37

def add_to_staxfile
  append_to_file 'Staxfile', "stack :#{@stack}, include: %w[DynamoDB]\n"
end

#append_include_templateObject



41
42
43
44
45
# File 'lib/generators/dynamo/dynamo_generator.rb', line 41

def append_include_template
  file = File.join('cf', "#{stack}.rb")
  create_file file, "description 'Dynamo tables'\n" unless File.exists?(file)
  append_to_file file, "include_template '#{stack}/dyn_#{table}.rb'\n"
end

#ask_for_attributesObject



22
23
24
25
26
27
28
29
30
# File 'lib/generators/dynamo/dynamo_generator.rb', line 22

def ask_for_attributes
  @attributes = []
  loop do
    name = ask('attribute name (blank when done)?')
    break if name.empty?
    type = ask('attribute type?', default: 'S')
    @attributes << [name, type]
  end
end

#ask_for_key_schemaObject



32
33
34
35
# File 'lib/generators/dynamo/dynamo_generator.rb', line 32

def ask_for_key_schema
  @hash  = ask('hash key?',  default: attributes[0].first)
  @range = ask('range key?', default: attributes[1].first)
end

#ask_for_optionsObject



18
19
20
# File 'lib/generators/dynamo/dynamo_generator.rb', line 18

def ask_for_options
  @stack = options[:stack] || ask('stack to use or create', default: 'dynamo')
end

#check_argsObject



12
13
14
15
16
# File 'lib/generators/dynamo/dynamo_generator.rb', line 12

def check_args
  usage! unless args.size == 1
  @table = args.first
  @id = "Dyn#{table.capitalize}"
end

#create_table_templateObject



47
48
49
# File 'lib/generators/dynamo/dynamo_generator.rb', line 47

def create_table_template
  template('dyn.rb.tt', File.join('cf', stack, "dyn_#{table}.rb"))
end