active_entity 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +5 -0
- data/README.md +11 -7
- data/Rakefile +7 -1
- data/active_entity.gemspec +10 -7
- data/lib/active_entity/attribute.rb +3 -14
- data/lib/active_entity/version.rb +1 -1
- data/lib/active_entity.rb +0 -3
- data/spec/active_entity/attribute_spec.rb +2 -1
- data/spec/readme_spec.rb +10 -0
- data/spec/spec_helper.rb +11 -0
- metadata +65 -26
- data/lib/active_entity/entity.rb +0 -13
- data/lib/active_entity/mutability.rb +0 -16
- data/lib/active_entity/strict_assignment.rb +0 -15
- data/spec/active_entity/mutability_spec.rb +0 -36
- data/spec/active_entity/strict_assignment_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1072bc0bff5756103e46f5e88ca83b624b43c7a2
|
4
|
+
data.tar.gz: 14e335691227ad6abd7045a4f33f6c0f89859966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2243185908d2889faa3ee05d8feb5dbe5b95e96a507a8bba191ce40784ad3637353d2587c2147757fab0c7f094644f5d9560f4179d1d6fd255008a7de4f7a20
|
7
|
+
data.tar.gz: aaea48011b23cb87fbe1a3140051aac64e6366799f64619dfaa34bb861cf2dc7b5439040a5e9ca1420278e670871380436ebac9ef7248eca3bbbe18cd8c1fed1
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
To make an entity with ease according to ActiveModel way.
|
4
4
|
|
5
|
+
[![Build Status](https://travis-ci.org/taiki45/active_entity.svg?branch=master)](https://travis-ci.org/taiki45/active_entity) [![Coverage Status](https://coveralls.io/repos/taiki45/active_entity/badge.svg)](https://coveralls.io/r/taiki45/active_entity) [![Code Climate](https://codeclimate.com/github/taiki45/active_entity/badges/gpa.svg)](https://codeclimate.com/github/taiki45/active_entity) [![Gem Version](https://badge.fury.io/rb/active_entity.svg)](http://badge.fury.io/rb/active_entity)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
```
|
11
|
+
```
|
10
12
|
gem 'active_entity'
|
11
13
|
```
|
12
14
|
|
@@ -22,7 +24,9 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
```ruby
|
24
26
|
class Message
|
25
|
-
include
|
27
|
+
include ActiveModel::Model
|
28
|
+
include ActiveEntity::Attribute
|
29
|
+
include ActiveEntity::Identity
|
26
30
|
|
27
31
|
attribute :title
|
28
32
|
attribute :body
|
@@ -34,15 +38,15 @@ class Message
|
|
34
38
|
end
|
35
39
|
|
36
40
|
message = Message.new(title: 'A README of ActiveEntity')
|
37
|
-
message.valid?
|
38
|
-
message.errors
|
41
|
+
expect(message.valid?).to be_falsy
|
42
|
+
expect(message.errors).to be_a(ActiveModel::Errors)
|
39
43
|
|
40
44
|
message = Message.new(title: 'A README of ActiveEntity', body: 'No contents!')
|
41
|
-
message.valid?
|
42
|
-
message.attributes
|
45
|
+
expect(message.valid?).to be_truthy
|
46
|
+
expect(message.attributes).to eq({ "title" => "A README of ActiveEntity", "body" => "No contents!" })
|
43
47
|
|
44
48
|
another_messsage = Message.new(title: 'A README of ActiveEntity', body: '')
|
45
|
-
message
|
49
|
+
expect(message).to eq(another_messsage)
|
46
50
|
```
|
47
51
|
|
48
52
|
## Contributing
|
data/Rakefile
CHANGED
data/active_entity.gemspec
CHANGED
@@ -6,11 +6,11 @@ require 'active_entity/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "active_entity"
|
8
8
|
spec.version = ActiveEntity::VERSION
|
9
|
-
spec.authors = ["Taiki
|
10
|
-
spec.email = ["
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description =
|
13
|
-
spec.homepage = ""
|
9
|
+
spec.authors = ["Taiki Ono"]
|
10
|
+
spec.email = ["taiks.4559@gmail.com"]
|
11
|
+
spec.summary = %q{An Active Model extention for entity.}
|
12
|
+
spec.description = %q{An extension for Active Model to encourage implementing entity.}
|
13
|
+
spec.homepage = "https://github.com/taiki45/active_entity"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -19,9 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "activemodel", ">= 4.0"
|
22
|
+
spec.add_dependency "activesupport", ">= 4.0"
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.1"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
25
|
spec.add_development_dependency "pry"
|
26
26
|
spec.add_development_dependency "pry-doc"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
29
|
+
spec.add_development_dependency "simplecov"
|
27
30
|
end
|
@@ -3,30 +3,19 @@ module ActiveEntity
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
class_attribute :defined_attributes,
|
7
|
-
instance_writer: false, instance_predicate: false
|
6
|
+
class_attribute :defined_attributes, instance_writer: false, instance_predicate: false
|
8
7
|
self.defined_attributes = {}
|
9
8
|
end
|
10
9
|
|
11
10
|
class_methods do
|
12
11
|
def attribute(name, options = {})
|
13
12
|
defined_attributes[name] = options
|
14
|
-
|
13
|
+
attr_accessor(name)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
def initialize(attrs = {})
|
19
|
-
attrs.each do |attr, value|
|
20
|
-
instance_variable_set(:"@#{attr}", value)
|
21
|
-
end if attrs.respond_to?(:each)
|
22
|
-
|
23
|
-
super()
|
24
|
-
end
|
25
|
-
|
26
17
|
def attributes
|
27
|
-
|
28
|
-
Hash[defined_attributes.keys.map {|name| [name, public_send(name)] }]
|
29
|
-
end
|
18
|
+
Hash[defined_attributes.keys.map {|name| [name.to_s, public_send(name)] }]
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
data/lib/active_entity.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe ActiveEntity::Attribute do
|
4
4
|
let(:test_class) do
|
5
5
|
Class.new do
|
6
|
+
include ActiveModel::Model
|
6
7
|
include ActiveEntity::Attribute
|
7
8
|
|
8
9
|
attribute :name
|
@@ -36,7 +37,7 @@ RSpec.describe ActiveEntity::Attribute do
|
|
36
37
|
it { is_expected.to be_kind_of(Hash) }
|
37
38
|
|
38
39
|
it "returns all attribute's name-value pairs" do
|
39
|
-
is_expected.to eq(name
|
40
|
+
is_expected.to eq('name' => 'Alice', 'age' => 1)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
data/spec/readme_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
require 'pry'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
Coveralls.wear!
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '/spec'
|
12
|
+
end
|
2
13
|
|
3
14
|
lib = File.expand_path('../lib', __FILE__)
|
4
15
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_entity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Taiki
|
7
|
+
- Taiki Ono
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,35 +53,35 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.7'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: coveralls
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
84
|
+
name: pry-doc
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,35 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
87
129
|
- - ">="
|
@@ -94,15 +136,17 @@ dependencies:
|
|
94
136
|
- - ">="
|
95
137
|
- !ruby/object:Gem::Version
|
96
138
|
version: '0'
|
97
|
-
description:
|
139
|
+
description: An extension for Active Model to encourage implementing entity.
|
98
140
|
email:
|
99
|
-
-
|
141
|
+
- taiks.4559@gmail.com
|
100
142
|
executables: []
|
101
143
|
extensions: []
|
102
144
|
extra_rdoc_files: []
|
103
145
|
files:
|
146
|
+
- ".coveralls.yml"
|
104
147
|
- ".gitignore"
|
105
148
|
- ".rspec"
|
149
|
+
- ".travis.yml"
|
106
150
|
- Gemfile
|
107
151
|
- LICENSE.txt
|
108
152
|
- README.md
|
@@ -110,17 +154,13 @@ files:
|
|
110
154
|
- active_entity.gemspec
|
111
155
|
- lib/active_entity.rb
|
112
156
|
- lib/active_entity/attribute.rb
|
113
|
-
- lib/active_entity/entity.rb
|
114
157
|
- lib/active_entity/identity.rb
|
115
|
-
- lib/active_entity/mutability.rb
|
116
|
-
- lib/active_entity/strict_assignment.rb
|
117
158
|
- lib/active_entity/version.rb
|
118
159
|
- spec/active_entity/attribute_spec.rb
|
119
160
|
- spec/active_entity/identity_spec.rb
|
120
|
-
- spec/
|
121
|
-
- spec/active_entity/strict_assignment_spec.rb
|
161
|
+
- spec/readme_spec.rb
|
122
162
|
- spec/spec_helper.rb
|
123
|
-
homepage:
|
163
|
+
homepage: https://github.com/taiki45/active_entity
|
124
164
|
licenses:
|
125
165
|
- MIT
|
126
166
|
metadata: {}
|
@@ -143,11 +183,10 @@ rubyforge_project:
|
|
143
183
|
rubygems_version: 2.2.2
|
144
184
|
signing_key:
|
145
185
|
specification_version: 4
|
146
|
-
summary:
|
186
|
+
summary: An Active Model extention for entity.
|
147
187
|
test_files:
|
148
188
|
- spec/active_entity/attribute_spec.rb
|
149
189
|
- spec/active_entity/identity_spec.rb
|
150
|
-
- spec/
|
151
|
-
- spec/active_entity/strict_assignment_spec.rb
|
190
|
+
- spec/readme_spec.rb
|
152
191
|
- spec/spec_helper.rb
|
153
192
|
has_rdoc:
|
data/lib/active_entity/entity.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveEntity
|
2
|
-
module StrictAssignment
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
def initialize(attrs = {})
|
6
|
-
keys = attrs.keys.map(&:to_sym) - defined_attributes.keys
|
7
|
-
|
8
|
-
unless keys.empty?
|
9
|
-
raise ArgumentError.new("Invalid assignments on: #{keys}")
|
10
|
-
end
|
11
|
-
|
12
|
-
super
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ActiveEntity::Mutability do
|
4
|
-
subject { test_class.new(x: 1) }
|
5
|
-
|
6
|
-
context 'when included after attribute definitions' do
|
7
|
-
before { test_class.send(:include, ActiveEntity::Mutability) }
|
8
|
-
|
9
|
-
let(:test_class) do
|
10
|
-
Class.new do
|
11
|
-
include ActiveEntity::Attribute
|
12
|
-
attribute :x
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'accepts attribute assign' do
|
17
|
-
expect { subject.x = 0 }.not_to raise_error
|
18
|
-
expect(subject.x).to eq(0)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when included before attribute definitions' do
|
23
|
-
let(:test_class) do
|
24
|
-
Class.new do
|
25
|
-
include ActiveEntity::Attribute
|
26
|
-
include ActiveEntity::Mutability
|
27
|
-
attribute :x
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'accepts attribute assign' do
|
32
|
-
expect { subject.x = 0 }.not_to raise_error
|
33
|
-
expect(subject.x).to eq(0)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ActiveEntity::StrictAssignment do
|
4
|
-
let(:test_class) do
|
5
|
-
Class.new do
|
6
|
-
include ActiveEntity::Attribute
|
7
|
-
include ActiveEntity::StrictAssignment
|
8
|
-
|
9
|
-
attribute :name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#initialize' do
|
14
|
-
context 'with valid mass assignment' do
|
15
|
-
it 'does not raise anything' do
|
16
|
-
expect { test_class.new(name: 'Alice') }.not_to raise_error
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with forbidden mass assignment' do
|
21
|
-
it 'raises ArgumentError' do
|
22
|
-
expect { test_class.new(x: 'x') }.to raise_error(ArgumentError)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|