Class: AwsRecord::Generators::ActiveModel
- Inherits:
-
Object
- Object
- AwsRecord::Generators::ActiveModel
- Defined in:
- lib/generators/aws_record/active_model.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.all(klass) ⇒ Object
GET index.
-
.build(klass, params = nil) ⇒ Object
GET new POST create.
-
.find(klass, attrs) ⇒ Object
GET show GET edit PATCH/PUT update DELETE destroy.
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE destroy.
-
#errors ⇒ Object
POST create PATCH/PUT update.
-
#initialize(name) ⇒ ActiveModel
constructor
A new instance of ActiveModel.
-
#save ⇒ Object
POST create.
-
#update(params = nil) ⇒ Object
PATCH/PUT update.
Constructor Details
#initialize(name) ⇒ ActiveModel
Returns a new instance of ActiveModel.
8 9 10 |
# File 'lib/generators/aws_record/active_model.rb', line 8 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/generators/aws_record/active_model.rb', line 6 def name @name end |
Class Method Details
.all(klass) ⇒ Object
GET index
13 14 15 |
# File 'lib/generators/aws_record/active_model.rb', line 13 def self.all(klass) "#{klass}.scan" end |
.build(klass, params = nil) ⇒ Object
GET new POST create
38 39 40 41 42 43 44 |
# File 'lib/generators/aws_record/active_model.rb', line 38 def self.build(klass, params = nil) if params "#{klass}.new(#{params})" else "#{klass}.new" end end |
.find(klass, attrs) ⇒ Object
GET show GET edit PATCH/PUT update DELETE destroy
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/aws_record/active_model.rb', line 21 def self.find(klass, attrs) hkey = attrs.select { |attr| attr.[:hash_key] }[0] rkey = attrs.select { |attr| attr.[:range_key] } rkey = rkey.empty? ? nil : rkey[0] if rkey "lambda { id = params[:id].split('&').map{ |param| CGI.unescape(param) } #{klass}.find(#{hkey.name}: id[0], #{rkey.name}: id[1]) }.call()" else "#{klass}.find(#{hkey.name}: CGI.unescape(params[:id]))" end end |
Instance Method Details
#destroy ⇒ Object
DELETE destroy
63 64 65 |
# File 'lib/generators/aws_record/active_model.rb', line 63 def destroy "#{name}.delete!" end |
#errors ⇒ Object
POST create PATCH/PUT update
58 59 60 |
# File 'lib/generators/aws_record/active_model.rb', line 58 def errors "#{name}.errors" end |
#save ⇒ Object
POST create
47 48 49 |
# File 'lib/generators/aws_record/active_model.rb', line 47 def save "#{name}.save" end |
#update(params = nil) ⇒ Object
PATCH/PUT update
52 53 54 |
# File 'lib/generators/aws_record/active_model.rb', line 52 def update(params = nil) "#{name}.update(#{params})" end |