entity_rb 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49b12775d7fcb0ae8b817244f35ab6933ad7de58
4
+ data.tar.gz: fa53e6f2c2aa14712ae617aa820a6957e6e3e5df
5
+ SHA512:
6
+ metadata.gz: 7feb84d0e330717f23c5a983df7b8591e1e9c1d7319d710fb6a3b72294055652759d091a8d686a4c46edf7fe94c97cb949fd079b8c7b0dfba98ae4d3b528e435
7
+ data.tar.gz: ed29751458490a55d778e8066eace696a9019703fd3f5503325adde92d9ddc9d2e0980c21c1a3c17ce31057f6d4d4a701b40ab9c724064b0b01f4ff5bc1cfdcf
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /.yardoc
12
+ /Gemfile.lock
13
+ /_yardoc/
14
+ *.bundle
15
+ *.so
16
+ *.o
17
+ *.a
18
+ mkmf.log
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+
25
+ ## Documentation cache and generated files:
26
+ /.yardoc/
27
+ /_yardoc/
28
+ /doc/
29
+ /rdoc/
30
+
31
+ ## Environment normalisation:
32
+ /.bundle/
33
+ /lib/bundler/man/
34
+
35
+ # for a library or gem, you might want to ignore these files since the code is
36
+ # intended to run in multiple environments; otherwise, check them in:
37
+ # Gemfile.lock
38
+ # .ruby-version
39
+ # .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in entity.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Caio Torres
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Entity
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'entity'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install entity
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/entity/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/entity_rb.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'entity_rb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "entity_rb"
8
+ spec.version = Entity::VERSION
9
+ spec.authors = ["Caio Torres e Paulo Patto"]
10
+ spec.email = ["caio.a.torres@gmail.com"]
11
+ spec.summary = %q{An Entity implementation to store all business logic from the (so called) model.}
12
+ spec.description = %q{An Entity implementation in ruby to store all business logic from the (so called) model.}
13
+ spec.homepage = "https://github.com/efreesen/entity_rb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(spec)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ end
data/lib/entity_rb.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "entity_rb/version"
2
+ require "entity_rb/base"
3
+
4
+ module Entity
5
+ end
@@ -0,0 +1,29 @@
1
+ module Entity
2
+ class Base
3
+ @@fields = []
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |key, value|
7
+ send("#{key}=", value) if @@fields.include? key.to_sym
8
+ end
9
+ end
10
+
11
+ protected
12
+ def self.field(key)
13
+ raise ArgumentError.new('Key must be a String, Symbol or Array') unless [String, Symbol, Array].include? key.class
14
+
15
+ if key.is_a? Array
16
+ key.each do |k|
17
+ begin
18
+ self.field k
19
+ rescue ArgumentError
20
+ end
21
+ end
22
+ else
23
+ @@fields.push key.to_sym
24
+
25
+ attr_accessor key.to_sym
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Entity
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,96 @@
1
+ require './lib/entity/base'
2
+
3
+ describe Entity::Base do
4
+ describe '.field' do
5
+ before do
6
+ class Test < Entity::Base
7
+ end
8
+ end
9
+
10
+ subject { Test.new }
11
+
12
+ context 'when key is passed' do
13
+ context 'and is a Symbol' do
14
+ before { Test.field :test_field }
15
+
16
+ it 'defines an attribute reader for it' do
17
+ expect(subject).to respond_to(:test_field)
18
+ end
19
+
20
+ it 'defines an attribute writer for it' do
21
+ expect(subject).to respond_to(:test_field=)
22
+ end
23
+ end
24
+
25
+ context 'and is a String' do
26
+ before { Test.field 'test_field' }
27
+
28
+ it 'defines an attribute reader for it' do
29
+ expect(subject).to respond_to(:test_field)
30
+ end
31
+
32
+ it 'defines an attribute writer for it' do
33
+ expect(subject).to respond_to(:test_field=)
34
+ end
35
+ end
36
+
37
+ context 'and is an Fixnum' do
38
+ it 'raises an ArgumentError' do
39
+ expect{Test.field 1}.to raise_error(ArgumentError)
40
+ end
41
+ end
42
+
43
+ context ', key is an Array' do
44
+ context 'and all elements are supported' do
45
+ before { Test.field ['field1', 'field2'] }
46
+
47
+ it 'creates an attribute reader for each attribute in array' do
48
+ expect(subject).to respond_to(:field1)
49
+ expect(subject).to respond_to(:field2)
50
+ end
51
+
52
+ it 'creates an attribute writer for each attribute in array' do
53
+ expect(subject).to respond_to(:field1=)
54
+ expect(subject).to respond_to(:field2=)
55
+ end
56
+ end
57
+
58
+ context 'and some elements are not supported' do
59
+ before { Test.field [1, 'field1', 2, 'field2'] }
60
+
61
+ it 'creates an attribute reader for the valid attributes' do
62
+ expect(subject).to respond_to(:field1)
63
+ expect(subject).to respond_to(:field2)
64
+ end
65
+
66
+ it 'does not create an attribute reader for the invalid attributes' do
67
+ expect(subject).not_to respond_to(:'1')
68
+ expect(subject).not_to respond_to(:'2')
69
+ end
70
+
71
+ it 'creates an attribute writer for the valid attributes' do
72
+ expect(subject).to respond_to(:field1=)
73
+ expect(subject).to respond_to(:field2=)
74
+ end
75
+
76
+ it 'does not create an attribute writer for the invalid attributes' do
77
+ expect(subject).not_to respond_to(:'1=')
78
+ expect(subject).not_to respond_to(:'2=')
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'and is a Hash' do
84
+ it 'raises an ArgumentError' do
85
+ expect{Test.field({})}.to raise_error(ArgumentError)
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'when key is not passed' do
91
+ it 'raises an ArgumentError' do
92
+ expect{Test.field}.to raise_error(ArgumentError)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.configure do |config|
2
+ config.order = :random
3
+
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.syntax = :expect
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.syntax = :expect
10
+
11
+ mocks.verify_partial_doubles = true
12
+ mocks.verify_doubled_constant_names = true
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: entity_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Caio Torres e Paulo Patto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: An Entity implementation in ruby to store all business logic from the
56
+ (so called) model.
57
+ email:
58
+ - caio.a.torres@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - entity_rb.gemspec
70
+ - lib/entity_rb.rb
71
+ - lib/entity_rb/base.rb
72
+ - lib/entity_rb/version.rb
73
+ - spec/entity/base_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/efreesen/entity_rb
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: An Entity implementation to store all business logic from the (so called)
99
+ model.
100
+ test_files:
101
+ - spec/entity/base_spec.rb
102
+ - spec/spec_helper.rb