passive_model 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4426f301237fd27c3c333bcc688149310fdce4d57621bd026b6baa6f64fd621e
4
- data.tar.gz: b0ed7ec5617fa39d2b9fe8ce12be19c8e67e45f316e4d692180d04ba4a6600a6
3
+ metadata.gz: cb48ebe8a0f354a6ef8ecebbbed4f8257854e09844ad57c5c82fdb09ef42e5ad
4
+ data.tar.gz: ea06363924c66cba7055becfc87b21a2fd025bc65f47b35d944797cb52d237ee
5
5
  SHA512:
6
- metadata.gz: '039752fb9fdee6627266c430d44e303564623b692d2f9f9184fd5f284435d79b0308790ac62343142563b684da01c5695bd749eb7a88a78b4e81f8654cfe235a'
7
- data.tar.gz: 9f7e1b1b562be197c2bd082d6affca432f0a8cfb0ea66c407cb87d390f2ab7b58ec760f43fd4a288aa02dadcabc036a3f9c2ef26ae28deef1c9ed6efe57e4f53
6
+ metadata.gz: c04ee7e7796735256f9dc3182121c272948a76cd00cee3db28d4812ae4cceaf848ea49f2890bddf16a0dabf47a3c1537287386919997a8ebb2a4b8231ea968b2
7
+ data.tar.gz: f06ec4476ae3e822fed9b494fb96a7c4d2d8a7205ecf44e5eeb5bfb99d88af926b67a4ff162d436d8862a38604ad3ac63f69301f661b0a5eb54d2f54ef93ca81
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # RailsNonPersistentModel
1
+ # PassiveModel
2
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.
3
+ This is a gem for using Rails ActiveModel functionalities without having an actual database table.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Supports validation, callbacks etc. And behaves like a model object, so can be replaced with actual model objects.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'rails_non_persistent_model'
12
+ gem 'passive_model'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -18,19 +18,78 @@ And then execute:
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install rails_non_persistent_model
21
+ $ gem install passive_model
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Create a class from `PassiveModel::Base`.
26
26
 
27
- ## Development
27
+ For example:
28
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.
29
+ ```erbruby
30
+ class ContactForm < PassiveModel::Base
31
+ attr_accessor :first_name, :last_name
30
32
 
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).
33
+ validates :first_name, presence: true
34
+ validates :last_name, presence: true
35
+ validate :first_name_is_not_spam
36
+
37
+ private
38
+
39
+ def first_name_is_not_spam
40
+ return if first_name.downcase != 'test'
32
41
 
33
- ## Contributing
42
+ errors.add(:first_name, 'is not valid')
43
+ end
44
+ end
45
+ ```
46
+
47
+ #### Create new objects
48
+
49
+ `form = ContactForm.new(first_name: 'John', last_name: 'Doe')`
50
+
51
+ #### Set attributes
52
+
53
+ `form.attributes = { first_name: 'Lewis' }`
54
+
55
+ #### Emulate a save
56
+
57
+ It runs the validations and also calls `before_save` callbacks if the object is valid
58
+
59
+ `form.save # returns true if valid?`
60
+
61
+ #### Emulate a save!
62
+
63
+ Raise an error if cannot be saved
34
64
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_non_persistent_model.
65
+ `form.save!`
66
+
67
+ #### persisted?
68
+
69
+ Return if save has been called
70
+
71
+ `form.persisted?`
72
+
73
+ #### before_save callback
74
+
75
+ Add a callback as follows:
76
+
77
+ ```erbruby
78
+ class ContactForm < PassiveModel::Base
79
+ before_save :send_info_to_mailchimp
80
+
81
+ validate :first_name, presence: true
82
+
83
+ private
84
+
85
+ def send_info_to_mailchimp
86
+ # API call
87
+ end
88
+ end
89
+ ```
90
+
91
+ The callback will be executed only if validations are clear.
92
+
93
+ ## Contributing
36
94
 
95
+ If you need more functionality, for bug reports raise a request at https://github.com/RocketApex/passive_model
@@ -1,3 +1,3 @@
1
1
  module PassiveModel
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan