Class: Stax::Generators::DynamoGenerator
- Inherits:
-
Base
- Object
- Base
- Stax::Generators::DynamoGenerator
- Defined in:
- lib/generators/dynamo/dynamo_generator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#id ⇒ Object
Returns the value of attribute id.
-
#range ⇒ Object
Returns the value of attribute range.
-
#stack ⇒ Object
Returns the value of attribute stack.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #add_to_staxfile ⇒ Object
- #append_include_template ⇒ Object
- #ask_for_attributes ⇒ Object
- #ask_for_key_schema ⇒ Object
- #ask_for_options ⇒ Object
- #check_args ⇒ Object
- #create_table_template ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10 def attributes @attributes end |
#hash ⇒ Object
Returns the value of attribute hash.
10 11 12 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10 def hash @hash end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10 def id @id end |
#range ⇒ Object
Returns the value of attribute range.
10 11 12 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10 def range @range end |
#stack ⇒ Object
Returns the value of attribute stack.
10 11 12 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 10 def stack @stack end |
#table ⇒ Object
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_staxfile ⇒ Object
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_template ⇒ Object
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_attributes ⇒ Object
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_schema ⇒ Object
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_options ⇒ Object
18 19 20 |
# File 'lib/generators/dynamo/dynamo_generator.rb', line 18 def @stack = [:stack] || ask('stack to use or create', default: 'dynamo') end |
#check_args ⇒ Object
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_template ⇒ Object
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 |