thyng 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 +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +2 -0
- data/lib/thyng.rb +26 -0
- data/lib/thyng/version.rb +3 -0
- data/tasks/test.rake +16 -0
- data/test/core/accessor_test.rb +23 -0
- data/test/core/initializer_test.rb +18 -0
- data/test/core/reader_test.rb +24 -0
- data/test/core/writer_test.rb +24 -0
- data/test/test_config.rb +2 -0
- data/test/version/version_test.rb +7 -0
- data/thyng.gemspec +40 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4c7db9aae62d6681d2dd971af42314dc2ea35fc
|
4
|
+
data.tar.gz: 9034618eaa475198878a3118f98cc4c0fef811f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea41f1e43df85be3bdd184e86bc6fd8312fec68d9c6712658eeaf30e3169b1b57e0055a9e56220ec42e8db723edaa515fa937cbfc9d4820065b3b3e439b86af5
|
7
|
+
data.tar.gz: 96cda3cee7960ec56f2950770977266a3ea920dce091ade504f334d024ca2190a4cdb4314231c53b3dbd97d4c6207ca3a325c553e4872c17de208ef5189d5a02
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Peter Saxton
|
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.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Thyng
|
2
|
+
|
3
|
+
##### Ruby objects with public state to encourage storage as data only collections.
|
4
|
+
|
5
|
+
### What?
|
6
|
+
A `thyng` is a ruby object with the convention of saving state in **key:value** pairs that are public on the object rather than in private **instance variables**.
|
7
|
+
|
8
|
+
### How?
|
9
|
+
Instead of private attributes a `thyng` has public aspects. Basic access to these can be declared with `asect_reader`, `aspect_write` & `aspect_accessor`.
|
10
|
+
|
11
|
+
### Why?
|
12
|
+
Will all internal state a `thyng` can be reconstructed completly from its data. This allows it to be passed as JSON a json object and easily be stored in a database.
|
13
|
+
|
14
|
+
### Simple example
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class Person < Thyng
|
18
|
+
aspect_accessor :name
|
19
|
+
end
|
20
|
+
|
21
|
+
person = Person.new
|
22
|
+
# => {}
|
23
|
+
|
24
|
+
person.name = 'Fester'
|
25
|
+
|
26
|
+
puts person
|
27
|
+
# => {name: 'Fester'}
|
28
|
+
```
|
29
|
+
|
30
|
+
### Show me the money
|
31
|
+
*Thyng objects are subclassed from ruby hashes. This means most database orm's know exactly how handle them*
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Person < Thyng
|
35
|
+
aspect_accessor :name
|
36
|
+
aspect_accessor :age
|
37
|
+
end
|
38
|
+
|
39
|
+
class Credentials < Thyng
|
40
|
+
aspect_accessor :email
|
41
|
+
crypted_accessor :password # <- Oooh!
|
42
|
+
end
|
43
|
+
|
44
|
+
person = Person.new name: 'Morticia', age: '41'
|
45
|
+
credentials = Credentials.new email: 'm@addams.biz', password: 'password'
|
46
|
+
|
47
|
+
record = Record.last
|
48
|
+
|
49
|
+
record.set person
|
50
|
+
record.set credentials
|
51
|
+
|
52
|
+
record.save
|
53
|
+
```
|
54
|
+
|
55
|
+
## Installation
|
56
|
+
|
57
|
+
Add this line to your application's Gemfile:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
gem 'thyng'
|
61
|
+
```
|
62
|
+
|
63
|
+
And then execute:
|
64
|
+
|
65
|
+
$ bundle
|
66
|
+
|
67
|
+
Or install it yourself as:
|
68
|
+
|
69
|
+
$ gem install thyng
|
70
|
+
|
71
|
+
## Usage
|
72
|
+
|
73
|
+
TODO: Write usage instructions here
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it ( https://github.com/[my-github-username]/thyng/fork )
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/thyng.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "thyng/version"
|
2
|
+
|
3
|
+
class Thyng < Hash
|
4
|
+
def initialize(args={})
|
5
|
+
args.each{ |attribute, value|
|
6
|
+
send("#{attribute}=", value)
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.aspect_writer aspect
|
11
|
+
define_method "#{aspect}=", ->(value) {
|
12
|
+
self[aspect] = value
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.aspect_reader aspect
|
17
|
+
define_method aspect, -> {
|
18
|
+
fetch(aspect)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.aspect_accessor aspect
|
23
|
+
aspect_reader aspect
|
24
|
+
aspect_writer aspect
|
25
|
+
end
|
26
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
|
4
|
+
|
5
|
+
test_tasks.each do |folder|
|
6
|
+
Rake::TestTask.new("test:#{folder}") do |test|
|
7
|
+
test.pattern = "test/#{folder}/**/*_test.rb"
|
8
|
+
test.verbose = true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Run application test suite"
|
13
|
+
Rake::TestTask.new("test") do |test|
|
14
|
+
test.pattern = "test/**/*_test.rb"
|
15
|
+
test.verbose = true
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../test_config'
|
2
|
+
|
3
|
+
class ReaderTest < MiniTest::Test
|
4
|
+
def gomez
|
5
|
+
'Gomez'
|
6
|
+
end
|
7
|
+
|
8
|
+
def accessor_example
|
9
|
+
@accessor_example ||= Class.new Thyng do
|
10
|
+
aspect_accessor :name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_accessor_sets_writer
|
15
|
+
example = accessor_example.new
|
16
|
+
assert example.respond_to?('name='), 'Should create writer method'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_responds_to_reader_method
|
20
|
+
example = accessor_example.new
|
21
|
+
assert example.respond_to?('name'), 'Should create reader method'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../test_config'
|
2
|
+
|
3
|
+
class InitializerTest < MiniTest::Test
|
4
|
+
def gomez
|
5
|
+
'Gomez'
|
6
|
+
end
|
7
|
+
|
8
|
+
def accessor_example
|
9
|
+
@accessor_example ||= Class.new Thyng do
|
10
|
+
aspect_accessor :name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sets_value_on_initialize
|
15
|
+
person = accessor_example.new name: gomez
|
16
|
+
assert_equal gomez, person.name
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../test_config'
|
2
|
+
|
3
|
+
class ReaderTest < MiniTest::Test
|
4
|
+
def gomez
|
5
|
+
'Gomez'
|
6
|
+
end
|
7
|
+
|
8
|
+
def reader_example
|
9
|
+
@reader_example ||= Class.new Thyng do
|
10
|
+
aspect_reader :name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_can_set_aspect
|
15
|
+
example = reader_example.new
|
16
|
+
example[:name] = gomez
|
17
|
+
assert_equal gomez, example.name
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_responds_to_reader_method
|
21
|
+
example = reader_example.new
|
22
|
+
assert example.respond_to?('name'), 'Thyng should report response to readers'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../test_config'
|
2
|
+
|
3
|
+
class WriterTest < MiniTest::Test
|
4
|
+
def gomez
|
5
|
+
'Gomez'
|
6
|
+
end
|
7
|
+
|
8
|
+
def writer_example
|
9
|
+
Class.new Thyng do
|
10
|
+
aspect_writer :name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_can_set_aspect
|
15
|
+
example = writer_example.new
|
16
|
+
example.name = gomez
|
17
|
+
assert_equal gomez, example[:name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_responds_to_writer_method
|
21
|
+
example = writer_example.new
|
22
|
+
assert example.respond_to?('name='), 'Thyng should report response to writers'
|
23
|
+
end
|
24
|
+
end
|
data/test/test_config.rb
ADDED
data/thyng.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thyng/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "thyng"
|
8
|
+
spec.version = Thyng::VERSION
|
9
|
+
spec.authors = ["Peter Saxton"]
|
10
|
+
spec.email = ["peterhsaxton@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby objects with public state to encourage storage as data only collections}
|
12
|
+
spec.description = %q{
|
13
|
+
Thyng
|
14
|
+
|
15
|
+
Ruby objects with public state to encourage storage as data only collections.
|
16
|
+
|
17
|
+
What?
|
18
|
+
|
19
|
+
A thyng is a ruby object with the convention of saving state in key:value pairs that are public on the object rather than in private instance variables.
|
20
|
+
|
21
|
+
How?
|
22
|
+
|
23
|
+
Instead of private attributes a thyng has public aspects. Basic access to these can be declared with asect_reader, aspect_write & aspect_accessor.
|
24
|
+
|
25
|
+
Why?
|
26
|
+
|
27
|
+
Will all internal state a thyng can be reconstructed completly from its data. This allows it to be passed as JSON a json object and easily be stored in a database.
|
28
|
+
}
|
29
|
+
spec.homepage = "https://github.com/CrowdHailer/Thyng"
|
30
|
+
spec.license = "MIT"
|
31
|
+
|
32
|
+
spec.files = `git ls-files -z`.split("\x0")
|
33
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
34
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "minitest", "~> 5.4.3"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thyng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Saxton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-24 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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.4.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.4.3
|
55
|
+
description: "\n Thyng\n \n Ruby objects with public state to encourage storage
|
56
|
+
as data only collections.\n\n What?\n\n A thyng is a ruby object with the
|
57
|
+
convention of saving state in key:value pairs that are public on the object rather
|
58
|
+
than in private instance variables.\n\n How?\n\n Instead of private attributes
|
59
|
+
a thyng has public aspects. Basic access to these can be declared with asect_reader,
|
60
|
+
aspect_write & aspect_accessor.\n\n Why?\n\n Will all internal state a thyng
|
61
|
+
can be reconstructed completly from its data. This allows it to be passed as JSON
|
62
|
+
a json object and easily be stored in a database.\n "
|
63
|
+
email:
|
64
|
+
- peterhsaxton@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/thyng.rb
|
75
|
+
- lib/thyng/version.rb
|
76
|
+
- tasks/test.rake
|
77
|
+
- test/core/accessor_test.rb
|
78
|
+
- test/core/initializer_test.rb
|
79
|
+
- test/core/reader_test.rb
|
80
|
+
- test/core/writer_test.rb
|
81
|
+
- test/test_config.rb
|
82
|
+
- test/version/version_test.rb
|
83
|
+
- thyng.gemspec
|
84
|
+
homepage: https://github.com/CrowdHailer/Thyng
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Ruby objects with public state to encourage storage as data only collections
|
108
|
+
test_files:
|
109
|
+
- test/core/accessor_test.rb
|
110
|
+
- test/core/initializer_test.rb
|
111
|
+
- test/core/reader_test.rb
|
112
|
+
- test/core/writer_test.rb
|
113
|
+
- test/test_config.rb
|
114
|
+
- test/version/version_test.rb
|