simple_objects 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/simple_objects/base.rb +59 -0
- data/lib/simple_objects/defaults.rb +23 -0
- data/lib/simple_objects/version.rb +3 -0
- data/lib/simple_objects.rb +7 -0
- data/simple_objects.gemspec +25 -0
- data/spec/lib/simple_objects/base_spec.rb +33 -0
- data/spec/spec_helper.rb +21 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 939d6dec189dfd4d07db852f4070b3ac9a4eb025
|
4
|
+
data.tar.gz: 6918a585dcafe58adfdc5854a1ce6fc407219f23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24078705f7012cb3ceb679862528b78312136aadba25a95fe16f7b48706510b9f9f2054468e1eee450ad59e7fd6f2c37e0580c11aab71c817dbd780741181e5c
|
7
|
+
data.tar.gz: c9c94f5390f310456c24ca9f26ce0fc150f6f56b859098d39cc357b1b629b2426a702c7908db0b9ec65ed76bb2d2223c8adb3ba24739f3f40844eab5f212e193
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sean
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# SimpleObject
|
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 'simple_object'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install simple_object
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/doomspork/simple_object/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,59 @@
|
|
1
|
+
require_relative 'defaults'
|
2
|
+
|
3
|
+
module SimpleObjects
|
4
|
+
module Base
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def attr_accessor(*attrs)
|
12
|
+
@attributes ||= []
|
13
|
+
@attributes.concat(attrs)
|
14
|
+
super(*attrs)
|
15
|
+
end
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
@attributes || []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(attributes = {})
|
23
|
+
values = defaults.merge(attributes)
|
24
|
+
values.each do |attr, value|
|
25
|
+
mthd = "#{attr}="
|
26
|
+
send(mthd, value) if self.respond_to?(mthd)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
attributes.each_with_object({}) do |k, hsh|
|
32
|
+
val = send(k)
|
33
|
+
if val.nil?
|
34
|
+
val = nil
|
35
|
+
elsif val.respond_to?(:to_h)
|
36
|
+
val = val.to_h
|
37
|
+
elsif val.respond_to?(:map)
|
38
|
+
val = val.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
|
39
|
+
end
|
40
|
+
hsh[k] = val
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def as_json(opts = {})
|
45
|
+
to_h.as_json(opts)
|
46
|
+
end
|
47
|
+
|
48
|
+
def cache_key
|
49
|
+
individual_key = [@id || 'new', @updated_at].reject(&:nil?).join('-')
|
50
|
+
"#{self.class.to_s.underscore}/#{individual_key}"
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def attributes
|
56
|
+
self.class.attributes
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SimpleObjects
|
2
|
+
module Defaults
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def attr_default(*defaults)
|
10
|
+
@defaults ||= {}
|
11
|
+
defaults.each { |default| @defaults.merge!(default) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def defaults
|
15
|
+
@defaults || {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def defaults
|
20
|
+
self.class.defaults
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_objects/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'simple_objects'
|
8
|
+
spec.version = SimpleObjects::VERSION
|
9
|
+
spec.authors = ['Sean Callan']
|
10
|
+
spec.email = ['seancallan@gmail.com']
|
11
|
+
spec.summary = 'Simple objects for Ruby'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
20
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
23
|
+
spec.add_development_dependency 'rspec-its', '~> 1.0'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SimpleObjects
|
4
|
+
describe Base do
|
5
|
+
|
6
|
+
class MockObject
|
7
|
+
include Base
|
8
|
+
|
9
|
+
attr_accessor :one, :two, :three
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
let(:args) do
|
14
|
+
{
|
15
|
+
one: 1,
|
16
|
+
two: 3
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { MockObject.new(args) }
|
21
|
+
|
22
|
+
its(:one) { is_expected.to eq 1 }
|
23
|
+
its(:two) { is_expected.to eq 3 }
|
24
|
+
its(:three) { is_expected.to be_nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#to_h' do
|
28
|
+
subject { MockObject.new(one: 'foo', two: 2).to_h }
|
29
|
+
|
30
|
+
it { is_expected.to include(one: 'foo', two: 2, three: nil) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
|
3
|
+
require 'coveralls'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'rspec/its'
|
6
|
+
|
7
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter 'spec'
|
11
|
+
coverage_dir 'docs/coverage'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'simple_objects'
|
15
|
+
|
16
|
+
Dir['spec/support/**/*.rb'].each { |f| require f }
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.pattern = '**/*_spec.rb'
|
20
|
+
config.mock_framework = :rspec
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_objects
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Callan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-08 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: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-its
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.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.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- seancallan@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/simple_objects.rb
|
110
|
+
- lib/simple_objects/base.rb
|
111
|
+
- lib/simple_objects/defaults.rb
|
112
|
+
- lib/simple_objects/version.rb
|
113
|
+
- simple_objects.gemspec
|
114
|
+
- spec/lib/simple_objects/base_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage:
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Simple objects for Ruby
|
140
|
+
test_files:
|
141
|
+
- spec/lib/simple_objects/base_spec.rb
|
142
|
+
- spec/spec_helper.rb
|