fob 0.0.1

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: 8295caa68f7d14f9ffa35c22ee410938eeeec580
4
+ data.tar.gz: 1123352e04f2b1841a22bb9190e1804e40248bc3
5
+ SHA512:
6
+ metadata.gz: 9189afea1e86b19ae692356abf6defe31986143a948c1e76c3ce39fd8df49f026983811bd60bf480a6d4b1d2da09fff55da1aa8a0bda27cae31d43a49c1d2276
7
+ data.tar.gz: 923c7d61a129b30034657e9edf1bc88a10d01167e2781d7e6270c2e79d1f05050f50000ed4660888406aff493bbd2e9f333dc3e10b67444ca47b2d735ad352e9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ #ruby=2.0.0
4
+ #ruby-gemset=fob
5
+
6
+ # Specify your gem's dependencies in fob.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 alexpeachey
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,35 @@
1
+ # Fob
2
+
3
+ Fob is a simple class you can subclass your Form Objects from. It includes ActiveModel and Virtus.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fob'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fob
18
+
19
+ ## Usage
20
+
21
+ class MyModel < Fob::Fob
22
+ represents :user, with: :username, :email
23
+ has_one :company, with: :name
24
+ attribute :remember_me, Boolean
25
+ validates :username, presence: true
26
+ validates :email, presence: true
27
+ end
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/fob.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 'fob/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fob"
8
+ spec.version = Fob::VERSION
9
+ spec.authors = ["Alex Peachey"]
10
+ spec.email = ["alex.peachey@gmail.com"]
11
+ spec.description = %q{Form OBjects made easy.}
12
+ spec.summary = %q{Don't bulk up your models or controllers. Stay away from accepts_nested_attributes_for. Put form logic where it belongs, in a FOB!}
13
+ spec.homepage = "https://github.com/alexpeachey/fob"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "virtus"
24
+ spec.add_development_dependency "activemodel"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "simplecov"
27
+ end
@@ -0,0 +1,3 @@
1
+ module Fob
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fob.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "fob/version"
2
+ require 'active_support/all'
3
+ require 'virtus'
4
+
5
+ module Fob
6
+
7
+ class Fob
8
+ include Virtus
9
+ extend ActiveModel::Naming
10
+ include ActiveModel::Conversion
11
+ include ActiveModel::Validations
12
+
13
+ def self.represents(name, options={})
14
+ include_model(name, options)
15
+ klass = name.to_s.split("_").collect(&:capitalize).join
16
+ singleton_class.instance_eval do
17
+ define_method(:model_name) do
18
+ ::ActiveModel::Name.new(self, nil, "#{klass}")
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.has_one(name, options={})
24
+ include_model(name, options)
25
+ end
26
+
27
+ def persisted?
28
+ false
29
+ end
30
+
31
+ private
32
+ def self.include_model(name, options)
33
+ class_eval("def #{name.to_s};@#{name.to_s};end")
34
+ class_eval("def #{name.to_s}=(val);@#{name.to_s}=val;end")
35
+ if options[:with]
36
+ delegate *(options[:with]), to: name
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fob::Fob do
4
+
5
+ describe '.represents' do
6
+ let(:form) do
7
+ Class.new(Fob::Fob) do
8
+ represents :string, with: [:length, :chars]
9
+ end
10
+ end
11
+
12
+ specify { expect(form.model_name).to eq 'String' }
13
+ specify { expect(form.new).to respond_to(:string) }
14
+ specify { expect(form.new).to respond_to(:string=) }
15
+ specify { expect(form.new).to respond_to(:length) }
16
+ specify { expect(form.new).to respond_to(:chars) }
17
+ end
18
+
19
+ describe '.has_one' do
20
+ let(:form) do
21
+ Class.new(Fob::Fob) do
22
+ has_one :string, with: [:length, :chars]
23
+ end
24
+ end
25
+
26
+ specify { expect(form.new).to respond_to(:string) }
27
+ specify { expect(form.new).to respond_to(:string=) }
28
+ specify { expect(form.new).to respond_to(:length) }
29
+ specify { expect(form.new).to respond_to(:chars) }
30
+ end
31
+
32
+ describe '#persisted?' do
33
+ let(:form) do
34
+ Class.new(Fob::Fob) do
35
+ end
36
+ end
37
+
38
+ specify { expect(form.new.persisted?).to eq false }
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+
5
+ SimpleCov.start do
6
+ command_name 'spec'
7
+ add_filter 'config/'
8
+ add_filter 'spec'
9
+ add_filter '.bundle'
10
+ minimum_coverage 100
11
+ end
12
+
13
+ require 'rspec'
14
+ require 'active_model'
15
+ require 'fob'
16
+
17
+ # require spec support files and shared behavior
18
+ Dir[File.expand_path('../shared/**/*.rb', __FILE__)].each { |file| require file }
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_with :rspec
22
+ config.treat_symbols_as_metadata_keys_with_true_values = true
23
+ config.run_all_when_everything_filtered = true
24
+ config.filter_run :focus
25
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fob
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Peachey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Form OBjects made easy.
98
+ email:
99
+ - alex.peachey@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - fob.gemspec
110
+ - lib/fob.rb
111
+ - lib/fob/version.rb
112
+ - spec/fob/fob_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: https://github.com/alexpeachey/fob
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Don't bulk up your models or controllers. Stay away from accepts_nested_attributes_for.
138
+ Put form logic where it belongs, in a FOB!
139
+ test_files:
140
+ - spec/fob/fob_spec.rb
141
+ - spec/spec_helper.rb