mumm_ra 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 +23 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.org +60 -0
- data/Rakefile +7 -0
- data/lib/mumm_ra/repository.rb +39 -0
- data/lib/mumm_ra/version.rb +3 -0
- data/lib/mumm_ra.rb +5 -0
- data/mumm_ra.gemspec +27 -0
- data/spec/mumm_ra/repository_spec.rb +89 -0
- data/spec/spec_helper.rb +8 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b56116cf0c2f38ffcd33d47713b225d1aa2ce32c
|
4
|
+
data.tar.gz: b1f7bbdb0ea444cd3d8607fe4b05f19ee16b4f79
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9649adfde955122dd05b9b1518fbb864aae28bfd9d785ec45b0e1e8a7772c7e28d6ae87440918277dd1a27bd41aee44c7e8e55cefc6eda9887d445b30fb73976
|
7
|
+
data.tar.gz: 8ada7bdf511d8b487a4b744790b39b60039fdc0e91b5b462779158828664ed0e85367eea4b2cb1fba37d86b34a744e634377516070542334924d9eace095d090
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
/README.html
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Federico Iachetti
|
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.org
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
* MummRa
|
2
|
+
[[https://travis-ci.org/iachettifederico/mumm_ra][Build State]] [[https://travis-ci.org/iachettifederico/mumm_ra.svg]]
|
3
|
+
|
4
|
+
This gem implements a simple Repository. It's ment to retrieve data from a source in a uniform way.
|
5
|
+
|
6
|
+
It's called after a cartoon character from the Thundercats show. This character is a wizard mummy with limited powers, but has the ability to turn itself into a powerful enemy with the help of ancient spirits.
|
7
|
+
|
8
|
+
It takes the analogy of simple mummy (raw data in the source) and powerful entity (fully quallified Ruby objects).
|
9
|
+
|
10
|
+
** Introduction
|
11
|
+
|
12
|
+
Say we have some data stored in a source. The data takes the form of two dimentional points, that has an =x= field and a =y= field.
|
13
|
+
|
14
|
+
We want to make a Repository capable of retreiving the stored data, allowing us not to worry about the output data.
|
15
|
+
|
16
|
+
This =Repository= should be placed between the ORM and Business layers of an application.
|
17
|
+
|
18
|
+
** Preconditions
|
19
|
+
*** The mapped object should comply with the following rules:
|
20
|
+
- It should be able to be initialized via a =Hash=
|
21
|
+
- It's class should have a =#members= method, that returns an array (or =Enumerable=) with the mane of the attributes as it's items (in the form of a =String= or =Symbol=)
|
22
|
+
- It has to have getters for every member
|
23
|
+
|
24
|
+
This behaviour could be easily achieved using the [[http://github.com/iachettifederico/rb_toolbox][rb_toolbox]] gem.
|
25
|
+
|
26
|
+
*** The source should comply with the following
|
27
|
+
- It should respond to the =#values= method, which sould return all the "stored" objects
|
28
|
+
- It should respond to the =#[]= method that, sould receive a key and return it's corresponding value
|
29
|
+
|
30
|
+
This behaviour could be easily achieved using a =Hash=.
|
31
|
+
|
32
|
+
*** Usage
|
33
|
+
|
34
|
+
TODO: Complete usage
|
35
|
+
|
36
|
+
** Installation
|
37
|
+
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
#+BEGIN_SRC ruby
|
41
|
+
gem 'mumm_ra'
|
42
|
+
#+END_SRC
|
43
|
+
|
44
|
+
And then execute:
|
45
|
+
#+BEGIN_SRC bash
|
46
|
+
$ bundle
|
47
|
+
#+END_SRC
|
48
|
+
|
49
|
+
Or install it yourself as:
|
50
|
+
#+BEGIN_SRC bash
|
51
|
+
$ gem install mumm_ra
|
52
|
+
#+END_SRC
|
53
|
+
|
54
|
+
** Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/[my-github-username]/mumm_ra/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module MummRa
|
2
|
+
class Repository
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(args={})
|
6
|
+
@source = args.fetch(:source)
|
7
|
+
@main_class = args.fetch(:main_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
def all
|
11
|
+
@all ||= source.values
|
12
|
+
end
|
13
|
+
|
14
|
+
def each
|
15
|
+
all.each do |value|
|
16
|
+
yield value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](key)
|
21
|
+
source[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def construct_from_object(obj)
|
25
|
+
return obj if obj.is_a? main_class
|
26
|
+
return main_class.new(obj) if obj.is_a?(Hash)
|
27
|
+
attrs = {}
|
28
|
+
main_class.members.each do |attr|
|
29
|
+
attrs[attr] = obj.send(attr)
|
30
|
+
end
|
31
|
+
main_class.new(attrs)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
attr_reader :source
|
36
|
+
attr_reader :main_class
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/mumm_ra.rb
ADDED
data/mumm_ra.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 'mumm_ra/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mumm_ra"
|
8
|
+
spec.version = MummRa::VERSION
|
9
|
+
spec.authors = ["Federico Iachetti"]
|
10
|
+
spec.email = ["iachetti.federico@gmail.com"]
|
11
|
+
spec.summary = %q{Provides a way to access data via a Repository object.}
|
12
|
+
spec.description = %q{Provides a way to access data via a Repository object.}
|
13
|
+
spec.homepage = ""
|
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{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rb_toolbox"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.12"
|
26
|
+
spec.add_development_dependency "rspec-given", "~> 3.5.4"
|
27
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "mumm_ra/repository"
|
3
|
+
require "ostruct"
|
4
|
+
require "rb_toolbox/struct"
|
5
|
+
|
6
|
+
Point = RbToolbox::Struct.new(:x, :y)
|
7
|
+
|
8
|
+
module MummRa
|
9
|
+
describe Repository do
|
10
|
+
context "initialization" do
|
11
|
+
context "with source and main_class" do
|
12
|
+
When(:repo) { Repository.new(source: :source, main_class: :main_class) }
|
13
|
+
Then { expect(repo).not_to have_failed }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "without source" do
|
17
|
+
When(:repo) { Repository.new(main_class: :main_class) }
|
18
|
+
Then { expect(repo).to have_failed(KeyError, "key not found: :source") }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "without main_class" do
|
22
|
+
When(:repo) { Repository.new(source: :source) }
|
23
|
+
Then { expect(repo).to have_failed(KeyError, "key not found: :main_class") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "enumeration" do
|
28
|
+
Given(:repo) { Repository.new(source: source, main_class: nil) }
|
29
|
+
Given(:source) {
|
30
|
+
{
|
31
|
+
"one" => "One",
|
32
|
+
"two" => "Two",
|
33
|
+
"three" => "Three",
|
34
|
+
}
|
35
|
+
}
|
36
|
+
Given(:values) { %W[One Two Three] }
|
37
|
+
Then { repo.all == values }
|
38
|
+
Then {
|
39
|
+
repo.each do |value|
|
40
|
+
value == values.shift
|
41
|
+
end
|
42
|
+
}
|
43
|
+
Then { repo.is_a? Enumerable }
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
context "fetching and constructing" do
|
48
|
+
Given(:main_class) { Point }
|
49
|
+
Given(:first) { Point.new(x: 0, y: 0) }
|
50
|
+
Given(:second) { Point.new(x: 1, y: 1) }
|
51
|
+
Given(:source) {
|
52
|
+
{
|
53
|
+
"first" => first,
|
54
|
+
"second" => second,
|
55
|
+
}
|
56
|
+
}
|
57
|
+
Given(:repo) { Repository.new(source: source, main_class: main_class) }
|
58
|
+
|
59
|
+
context "#[]" do
|
60
|
+
Then { repo["first"] == first }
|
61
|
+
Then { repo["third"] == nil }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "#construct_from_object" do
|
65
|
+
#Invariable { repo.construct_from_object.is_a?(main_class) }
|
66
|
+
Given(:point) { Point.new(x: 1, y: 2) }
|
67
|
+
Given(:hash) { {x: 3, y: 4} }
|
68
|
+
Given(:object) { OpenStruct.new(x: 5, y: 6) }
|
69
|
+
|
70
|
+
When(:point1) { repo.construct_from_object(point) }
|
71
|
+
When(:point2) { repo.construct_from_object(hash) }
|
72
|
+
When(:point3) { repo.construct_from_object(object) }
|
73
|
+
|
74
|
+
Then { point1.is_a? Point }
|
75
|
+
Then { point1.x == 1 }
|
76
|
+
Then { point1.y == 2 }
|
77
|
+
|
78
|
+
Then { point2.is_a? Point }
|
79
|
+
Then { point2.x == 3 }
|
80
|
+
Then { point2.y == 4 }
|
81
|
+
|
82
|
+
Then { point3.is_a? Point }
|
83
|
+
Then { point3.x == 5 }
|
84
|
+
Then { point3.y == 6 }
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mumm_ra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Federico Iachetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb_toolbox
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-given
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.5.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.5.4
|
83
|
+
description: Provides a way to access data via a Repository object.
|
84
|
+
email:
|
85
|
+
- iachetti.federico@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.org
|
95
|
+
- Rakefile
|
96
|
+
- lib/mumm_ra.rb
|
97
|
+
- lib/mumm_ra/repository.rb
|
98
|
+
- lib/mumm_ra/version.rb
|
99
|
+
- mumm_ra.gemspec
|
100
|
+
- spec/mumm_ra/repository_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Provides a way to access data via a Repository object.
|
126
|
+
test_files:
|
127
|
+
- spec/mumm_ra/repository_spec.rb
|
128
|
+
- spec/spec_helper.rb
|