soulless 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed8e30f22d775b7646b996ff1a6ecf92ec96fe98
4
+ data.tar.gz: 288d8bf2b2b3b077e0369477168f4ff6e1bdacd3
5
+ SHA512:
6
+ metadata.gz: bd80dec834541eb84183a91486b1e18d0dd5d35385b01a0cce3bf096ea8fa6d85f22eaeb181d2432bf3d90d1ce67086c53440ea0257fa3de90e7f0456d555cec
7
+ data.tar.gz: faa287251a4f8ceaf9ef077d02279ece8755c55517d685a1c57d4da3c9f441e5d24d2428a22994d18cb9efb011a5b9caab6b0a3799a3ecdd12f646a4609dee5f
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv*
19
+ .rvmrc
20
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ - jruby-19mode
7
+ - jruby-head
8
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ar_book_finder.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'bundler'
8
+ gem 'coveralls', require: false
9
+ gem 'rake'
10
+ end
11
+
12
+ group :test do
13
+ gem 'rspec'
14
+ gem 'simplecov'
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anthony Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Soulless
2
+
3
+ Rails models without the database (and Rails).
4
+
5
+ [![Build Status](https://travis-ci.org/anthonator/soulless.png?branch=master)](https://travis-ci.org/anthonator/soulless) [![Dependency Status](https://gemnasium.com/anthonator/soulless.png)](https://gemnasium.com/anthonator/soulless)
6
+ [![Coverage Status](https://coveralls.io/repos/anthonator/soulless/badge.png?branch=master)](https://coveralls.io/r/anthonator/soulless?branch=master) [![Code Climate](https://codeclimate.com/github/anthonator/soulless.png)](https://codeclimate.com/github/anthonator/soulless)
7
+
8
+ Great for implementing the form object pattern. [Check out #3](http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/) of this great article by @brynary for more information on the form object pattern.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'soulless'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install soulless
23
+
24
+ ## Usage
25
+
26
+ Just define a plain-old-ruby-object and get crackin'!
27
+
28
+ ```ruby
29
+ class UserSignupForm
30
+ include Soulless.model
31
+
32
+ attribute :email, String
33
+ attribute :name, String
34
+ attribute :password
35
+ attribute :super_awesome, Boolean, default: false
36
+
37
+ validates :email, presence: true
38
+
39
+ validates :name, presence: true
40
+
41
+ validates :password, presence: true,
42
+ lenght: { is_at_least: 8 }
43
+
44
+ private
45
+ def persist!
46
+ # You're gonna need this!
47
+ # Define what to do with this form when ready to save here.
48
+ end
49
+ end
50
+ ```
51
+
52
+ Awesome. Now let's do something with it.
53
+
54
+ ```ruby
55
+ UsersController < ApplicationController
56
+ def create
57
+ @form = UserSignupForm.new(params.permit(user: [:email, :name, :password, :super_awesome]))
58
+ if @form.save
59
+ # do something here
60
+ else
61
+ render :new
62
+ end
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### Configuration
68
+
69
+ ```ruby
70
+ class UserSignupForm
71
+ # include attribute DSL + constructor + mass-assignment
72
+ include Soulless.model
73
+ end
74
+ ```
75
+
76
+ ```ruby
77
+ class UserSignupForm
78
+ # include attribute DSL + constructor
79
+ include Soulless.model(mass_assignment: false)
80
+ end
81
+ ```
82
+
83
+ ```ruby
84
+ class UserSignupForm
85
+ # include attribute DSL
86
+ include Soulless.model(constructor: false, mass_assignment: false)
87
+ end
88
+ ```
89
+
90
+ ### Batteries included...
91
+
92
+ The great thing about Soulless? Rails isn't required.
93
+
94
+ ### This looks familir...
95
+
96
+ You noticed? We're using Virtus to power this gem. That means you get all the Virtus goodies for free. Check out [their GitHub page](https://github.com/solnic/virtus) to see what's up.
97
+
98
+ ## Contributing
99
+
100
+ 1. Fork it
101
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
102
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
103
+ 4. Push to the branch (`git push origin my-new-feature`)
104
+ 5. Create new Pull Request
105
+
106
+ ## Credits
107
+ [![Sticksnleaves](http://sticksnleaves-wordpress.herokuapp.com/wp-content/themes/sticksnleaves/images/snl-logo-116x116.png)](http://www.sticksnleaves.com)
108
+
109
+ Soulless is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
110
+
111
+ Thanks to all of our [contributors](https://github.com/anthonator/soulless/graphs/contributors)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task default: :spec
@@ -0,0 +1,34 @@
1
+ module Soulless
2
+ module Model
3
+ def self.included(base)
4
+ base.class_eval do
5
+ extend ActiveModel::Naming
6
+ include ActiveModel::Conversion
7
+ include ActiveModel::Validations
8
+
9
+ def persisted?
10
+ false
11
+ end
12
+
13
+ def save
14
+ if valid?
15
+ persist!
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+
22
+ def update_attributes(attributes)
23
+ self.attributes = attributes
24
+ save
25
+ end
26
+
27
+ private
28
+ def persist!
29
+ raise 'Method persist! not defined...'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Soulless
2
+ VERSION = "0.1.0"
3
+ end
data/lib/soulless.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'virtus'
2
+ require 'active_support/core_ext/class/attribute'
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'active_support/callbacks'
5
+ require 'active_support/concern'
6
+ require 'active_model/naming'
7
+ require 'active_model/translation'
8
+ require 'active_model/callbacks'
9
+ require 'active_model/validator'
10
+ require 'active_model/errors'
11
+ require 'active_model/validations'
12
+ require 'active_model/conversion'
13
+
14
+ require 'soulless/model'
15
+ require 'soulless/version'
16
+
17
+ module Soulless
18
+ def self.model(options = {})
19
+ mod = Module.new
20
+ mod.define_singleton_method :included do |object|
21
+ object.send(:include, Virtus.model(options))
22
+ object.send(:include, Model)
23
+ end
24
+ mod
25
+ end
26
+ end
data/soulless.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soulless/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'soulless'
8
+ spec.version = Soulless::VERSION
9
+ spec.authors = ['Anthony Smith']
10
+ spec.email = ['anthony@sticksnleaves.com']
11
+ spec.description = %q{Models without a soul.}
12
+ spec.summary = %q{Create Rails style models without the database.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '>= 3.2'
22
+ spec.add_runtime_dependency 'activemodel', '>= 3.2'
23
+ spec.add_runtime_dependency 'virtus', '>= 1.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Soulless do
4
+ before(:each) do
5
+ @dummy_class = DummyClass.new
6
+ end
7
+
8
+ it 'should validate name' do
9
+ @dummy_class.name = nil
10
+ @dummy_class.valid?.should == false
11
+ @dummy_class.errors[:name].should_not be_empty
12
+ end
13
+
14
+ it 'should call #persist! when #save is called' do
15
+ @dummy_class.save
16
+ @dummy_class.saved.should be_true
17
+ end
18
+
19
+ it 'should not call #persist! if attributes are invalid' do
20
+ @dummy_class.name = nil
21
+ @dummy_class.save.should be_false
22
+ @dummy_class.saved.should be_false
23
+ end
24
+
25
+ it '#update_attributes should update multiple attributes and then save' do
26
+ @dummy_class.update_attributes(name: 'Yaw', email: 'yokoono@thebeatles.com')
27
+ @dummy_class.name.should == 'Yaw'
28
+ @dummy_class.email.should == 'yokoono@thebeatles.com'
29
+ @dummy_class.saved.should be_true
30
+ end
31
+
32
+ it '#persisted? should be false' do
33
+ @dummy_class.persisted?.should be_false
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'soulless'
5
+
6
+ # Require supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| puts f; require f }
@@ -0,0 +1,14 @@
1
+ class DummyClass
2
+ include Soulless.model
3
+
4
+ attribute :name, String, default: 'Anthony'
5
+ attribute :email, String
6
+ attribute :saved, Boolean, default: false
7
+
8
+ validates :name, presence: true
9
+
10
+ private
11
+ def persist!
12
+ self.saved = true
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soulless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Models without a soul.
84
+ email:
85
+ - anthony@sticksnleaves.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/soulless.rb
97
+ - lib/soulless/model.rb
98
+ - lib/soulless/version.rb
99
+ - soulless.gemspec
100
+ - spec/soulless_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/dummy_class.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Create Rails style models without the database.
127
+ test_files:
128
+ - spec/soulless_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/dummy_class.rb