aws-record-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +175 -0
- data/VERSION +1 -0
- data/lib/aws-record-rails.rb +28 -0
- data/lib/generators/aws_record/active_model.rb +68 -0
- data/lib/generators/aws_record/base.rb +212 -0
- data/lib/generators/aws_record/erb/erb_generator.rb +55 -0
- data/lib/generators/aws_record/erb/templates/_form.html.erb.tt +34 -0
- data/lib/generators/aws_record/erb/templates/edit.html.erb.tt +6 -0
- data/lib/generators/aws_record/erb/templates/index.html.erb.tt +31 -0
- data/lib/generators/aws_record/erb/templates/new.html.erb.tt +5 -0
- data/lib/generators/aws_record/erb/templates/show.html.erb.tt +11 -0
- data/lib/generators/aws_record/model/USAGE +24 -0
- data/lib/generators/aws_record/model/model_generator.rb +25 -0
- data/lib/generators/aws_record/model/templates/model.rb.tt +76 -0
- data/lib/generators/aws_record/model/templates/table_config.rb.tt +20 -0
- data/lib/generators/aws_record/resource/USAGE +23 -0
- data/lib/generators/aws_record/resource/resource_generator.rb +21 -0
- data/lib/generators/aws_record/scaffold/USAGE +31 -0
- data/lib/generators/aws_record/scaffold/scaffold_generator.rb +46 -0
- data/lib/generators/aws_record/scaffold/templates/scaffold.css +80 -0
- data/lib/generators/aws_record/scaffold_controller/USAGE +15 -0
- data/lib/generators/aws_record/scaffold_controller/scaffold_controller_generator.rb +51 -0
- data/lib/generators/aws_record/scaffold_controller/templates/api_controller.rb.tt +63 -0
- data/lib/generators/aws_record/scaffold_controller/templates/controller.rb.tt +70 -0
- data/lib/generators/generated_attribute.rb +139 -0
- data/lib/generators/secondary_index.rb +67 -0
- data/lib/tasks/aws_record/migrate.rake +14 -0
- metadata +99 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AwsRecord
|
4
|
+
module Generators
|
5
|
+
# @api private
|
6
|
+
class SecondaryIndex
|
7
|
+
PROJ_TYPES = %w[ALL KEYS_ONLY INCLUDE].freeze
|
8
|
+
attr_reader :name, :hash_key, :range_key, :projection_type
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def parse(key_definition)
|
12
|
+
name, index_options = key_definition.split(':')
|
13
|
+
index_options = index_options.split(',') if index_options
|
14
|
+
opts = parse_raw_options(index_options)
|
15
|
+
|
16
|
+
new(name, opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_raw_options(raw_opts)
|
22
|
+
raw_opts ||= []
|
23
|
+
raw_opts.to_h { |opt| get_option_value(opt) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_option_value(raw_option)
|
27
|
+
case raw_option
|
28
|
+
|
29
|
+
when /hkey\{(\w+)\}/
|
30
|
+
[:hash_key, ::Regexp.last_match(1)]
|
31
|
+
when /rkey\{(\w+)\}/
|
32
|
+
[:range_key, ::Regexp.last_match(1)]
|
33
|
+
when /proj_type\{(\w+)\}/
|
34
|
+
[:projection_type, ::Regexp.last_match(1)]
|
35
|
+
else
|
36
|
+
raise ArgumentError, "Invalid option for secondary index #{raw_option}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(name, opts)
|
42
|
+
raise ArgumentError, 'You must provide a name' unless name
|
43
|
+
raise ArgumentError, 'You must provide a hash key' unless opts[:hash_key]
|
44
|
+
|
45
|
+
if opts.key? :projection_type
|
46
|
+
unless PROJ_TYPES.include? opts[:projection_type]
|
47
|
+
raise ArgumentError, "Invalid projection type #{opts[:projection_type]}"
|
48
|
+
end
|
49
|
+
if opts[:projection_type] != 'ALL'
|
50
|
+
raise NotImplementedError, 'ALL is the only projection type currently supported'
|
51
|
+
end
|
52
|
+
else
|
53
|
+
opts[:projection_type] = 'ALL'
|
54
|
+
end
|
55
|
+
|
56
|
+
if opts[:hash_key] == opts[:range_key]
|
57
|
+
raise ArgumentError, "#{opts[:hash_key]} cannot be both the rkey and hkey for gsi #{name}"
|
58
|
+
end
|
59
|
+
|
60
|
+
@name = name
|
61
|
+
@hash_key = opts[:hash_key]
|
62
|
+
@range_key = opts[:range_key]
|
63
|
+
@projection_type = "\"#{opts[:projection_type]}\""
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc 'Run all table configs in db/table_config folder'
|
4
|
+
namespace :aws_record do
|
5
|
+
task migrate: :environment do
|
6
|
+
Dir[File.join('db', 'table_config', '**/*.rb')].each do |filename|
|
7
|
+
puts "running #{filename}.rb"
|
8
|
+
require(File.expand_path(filename))
|
9
|
+
|
10
|
+
table_config = ModelTableConfig.config
|
11
|
+
table_config.migrate! unless table_config.compatible?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-record-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amazon Web Services
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-record
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.1.0
|
41
|
+
description: Includes Aws::Record scaffold generators for Rails
|
42
|
+
email:
|
43
|
+
- aws-dr-rubygems@amazon.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE
|
50
|
+
- VERSION
|
51
|
+
- lib/aws-record-rails.rb
|
52
|
+
- lib/generators/aws_record/active_model.rb
|
53
|
+
- lib/generators/aws_record/base.rb
|
54
|
+
- lib/generators/aws_record/erb/erb_generator.rb
|
55
|
+
- lib/generators/aws_record/erb/templates/_form.html.erb.tt
|
56
|
+
- lib/generators/aws_record/erb/templates/edit.html.erb.tt
|
57
|
+
- lib/generators/aws_record/erb/templates/index.html.erb.tt
|
58
|
+
- lib/generators/aws_record/erb/templates/new.html.erb.tt
|
59
|
+
- lib/generators/aws_record/erb/templates/show.html.erb.tt
|
60
|
+
- lib/generators/aws_record/model/USAGE
|
61
|
+
- lib/generators/aws_record/model/model_generator.rb
|
62
|
+
- lib/generators/aws_record/model/templates/model.rb.tt
|
63
|
+
- lib/generators/aws_record/model/templates/table_config.rb.tt
|
64
|
+
- lib/generators/aws_record/resource/USAGE
|
65
|
+
- lib/generators/aws_record/resource/resource_generator.rb
|
66
|
+
- lib/generators/aws_record/scaffold/USAGE
|
67
|
+
- lib/generators/aws_record/scaffold/scaffold_generator.rb
|
68
|
+
- lib/generators/aws_record/scaffold/templates/scaffold.css
|
69
|
+
- lib/generators/aws_record/scaffold_controller/USAGE
|
70
|
+
- lib/generators/aws_record/scaffold_controller/scaffold_controller_generator.rb
|
71
|
+
- lib/generators/aws_record/scaffold_controller/templates/api_controller.rb.tt
|
72
|
+
- lib/generators/aws_record/scaffold_controller/templates/controller.rb.tt
|
73
|
+
- lib/generators/generated_attribute.rb
|
74
|
+
- lib/generators/secondary_index.rb
|
75
|
+
- lib/tasks/aws_record/migrate.rake
|
76
|
+
homepage: https://github.com/aws/aws-record-rails
|
77
|
+
licenses:
|
78
|
+
- Apache-2.0
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.7'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.5.11
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Aws::Record integration for Rails
|
99
|
+
test_files: []
|