passive_model 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/lib/passive_model/base.rb +58 -0
- data/lib/passive_model/version.rb +3 -0
- data/lib/rails_non_persistent_model.rb +6 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee4b6e1676367d37ea0f49d020110ed46c65defb3b5e01bfe8c179cfe7833326
|
4
|
+
data.tar.gz: 06d1bb11887910e53035da69c7c84bff5f2c19f57da66591c47ae7bc596a76d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 864bb58934aabd4bd10d2dcb47db00cf9ad10456a2aa2c85d895e6005cb0df586a78dd9fb3a42c354c85f7282befec664de5327d905c28ab36eebc26850c09b6
|
7
|
+
data.tar.gz: ba16f687fa192d25f1b40558db94bbd55a6e8a95fbbcd6868516630febdfd70b952dd7f3d43a217b4f7c40312c34d040236179cc19cbe1b6bcb0a372e6815d0a
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Jey Geethan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# RailsNonPersistentModel
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_non_persistent_model`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rails_non_persistent_model'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rails_non_persistent_model
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_non_persistent_model.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PassiveModel
|
4
|
+
# Class to be a parent class for all model-like classes where you need validations etc
|
5
|
+
# To be used for forms and to be mapped to each form independently
|
6
|
+
# Behaves like a active record model without the corresponding table
|
7
|
+
# Supports before_validation after_validation callbacks
|
8
|
+
# Supports before_save (gets run only if valid) - this is a custom implementation
|
9
|
+
# Supports passing the attributes .new and .attributes
|
10
|
+
class Base
|
11
|
+
include ActiveModel::Validations
|
12
|
+
include ActiveModel::Validations::Callbacks
|
13
|
+
include ActiveModel::Conversion
|
14
|
+
extend ActiveModel::Naming
|
15
|
+
|
16
|
+
def initialize(hash = {})
|
17
|
+
set_attributes(hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
def attributes=(hash = {})
|
21
|
+
set_attributes(hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
return false unless self.valid?
|
26
|
+
|
27
|
+
execute_callbacks(@@before_save_callbacks)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def save!
|
32
|
+
raise(ActiveRecord::RecordInvalid) unless self.save
|
33
|
+
end
|
34
|
+
|
35
|
+
def persisted?
|
36
|
+
@persisted || false
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def execute_callbacks(callbacks)
|
42
|
+
(callbacks || []).each do |callback|
|
43
|
+
self.send(callback.to_sym)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.before_save(name)
|
48
|
+
@@before_save_callbacks ||= []
|
49
|
+
@@before_save_callbacks << name
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_attributes(hash)
|
53
|
+
hash.keys.each do |key|
|
54
|
+
instance_variable_set('@' + key.to_s, hash[key])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: passive_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jey Geethan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.0
|
27
|
+
description: Get the benefits of models without having to save them to the database
|
28
|
+
in rails
|
29
|
+
email:
|
30
|
+
- opensource@rocketapex.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/passive_model/base.rb
|
39
|
+
- lib/passive_model/version.rb
|
40
|
+
- lib/rails_non_persistent_model.rb
|
41
|
+
homepage: https://github.com/RocketApex/passive_model
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
allowed_push_host: https://rubygems.org
|
46
|
+
homepage_uri: https://github.com/RocketApex/passive_model
|
47
|
+
source_code_uri: https://github.com/RocketApex/passive_model
|
48
|
+
changelog_uri: https://github.com/RocketApex/passive_model
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.3.0
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.3.7
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: For using models without saving to the database
|
68
|
+
test_files: []
|