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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47be0a7e04d9be58924ae62eb75767f415e87e89
4
- data.tar.gz: c00c8b1651220fc744e68f0fc9097ab71505df2f
3
+ metadata.gz: 1072bc0bff5756103e46f5e88ca83b624b43c7a2
4
+ data.tar.gz: 14e335691227ad6abd7045a4f33f6c0f89859966
5
5
  SHA512:
6
- metadata.gz: 8014240c2bac204b34fbecef8cbc3f31ad4f2c353bd7d3573d89397902d1db56bf0e5c3ecdfe58eaa52a7e006b1f64608ea7a545eaf1ee92eaff0b1de7c0dd12
7
- data.tar.gz: fdd4e6a0b67f756dece737e2076cf496dd02021412ff2156f8a6eda88cf5d39f3c967500b1f11b2282271ac1b9bd505bef75bdc276da00f98d594a082c37f3eb
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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
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
- ```ruby
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 ActiveEntity::Entity
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? #=> false
38
- message.errors #=> returns a ActiveModel::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? #=> true
42
- message.attributes #=> { title: "A README of ActiveEntity", body: "No contents!" }
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 == another_messsage #=> true
49
+ expect(message).to eq(another_messsage)
46
50
  ```
47
51
 
48
52
  ## Contributing
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['-c', '-fd']
6
+ end
7
+ task :default => :spec
2
8
 
@@ -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 ONO"]
10
- spec.email = ["taiki-ono@cookpad.com"]
11
- spec.summary = %q{To make an entity with ease according to ActiveModel way.}
12
- spec.description = spec.summary
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 "rake", "~> 10.0"
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
- attr_reader(name)
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
- @_attributes ||= begin
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
@@ -1,3 +1,3 @@
1
1
  module ActiveEntity
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/active_entity.rb CHANGED
@@ -4,6 +4,3 @@ require 'active_support/concern'
4
4
  require 'active_entity/version'
5
5
  require 'active_entity/attribute'
6
6
  require 'active_entity/identity'
7
- require 'active_entity/strict_assignment'
8
- require 'active_entity/entity'
9
- require 'active_entity/mutability'
@@ -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: 'Alice', age: 1)
40
+ is_expected.to eq('name' => 'Alice', 'age' => 1)
40
41
  end
41
42
  end
42
43
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'README code snipets' do
4
+ let(:readme) { File.read(File.expand_path('../../README.md', __FILE__)) }
5
+ let(:code) { readme.slice(/^```ruby$\n(.*)^```$/m, 1) }
6
+
7
+ it 'runs suceessfully' do
8
+ eval(code)
9
+ end
10
+ end
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.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Taiki ONO
7
+ - Taiki Ono
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
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: rake
56
+ name: coveralls
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
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: '10.0'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec
70
+ name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '3.1'
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: '3.1'
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: pry-doc
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: To make an entity with ease according to ActiveModel way.
139
+ description: An extension for Active Model to encourage implementing entity.
98
140
  email:
99
- - taiki-ono@cookpad.com
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/active_entity/mutability_spec.rb
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: To make an entity with ease according to ActiveModel way.
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/active_entity/mutability_spec.rb
151
- - spec/active_entity/strict_assignment_spec.rb
190
+ - spec/readme_spec.rb
152
191
  - spec/spec_helper.rb
153
192
  has_rdoc:
@@ -1,13 +0,0 @@
1
- module ActiveEntity
2
- module Entity
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include Attribute
7
- include StrictAssignment
8
- include Identity
9
- include ActiveModel::Validations
10
- include ActiveModel::Serialization
11
- end
12
- end
13
- end
@@ -1,16 +0,0 @@
1
- module ActiveEntity
2
- module Mutability
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- attr_writer(*defined_attributes.keys)
7
- end
8
-
9
- class_methods do
10
- def attribute(name, option = {})
11
- super
12
- attr_writer(name)
13
- end
14
- end
15
- end
16
- end
@@ -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