data_contract 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95fd1fd64251742ff7636bba6474cd91bdf5bec9
4
+ data.tar.gz: 1180fa320ad2f4fc4e90bde008ad5f181690ce2d
5
+ SHA512:
6
+ metadata.gz: 9cf561c4afc12f8178b9eb731008d8db3d6068754ec821c515ec366f981728874b8ea639ef6e51011950835219c6c0e6c0dac4ea7c606bfddaf2a4567f64eab4
7
+ data.tar.gz: 834cb5321baf48eecb599c01ed54d1cc94417e206a8c212d0f472cefbdb027aea7ce014c8f69f5118dab5366899ea3453c9a0109a5688045ae8c8668573774e3
@@ -0,0 +1,2 @@
1
+ require 'data_contract/data_contract'
2
+ require 'data_contract/implementation'
@@ -0,0 +1,16 @@
1
+ class DataContract < Module
2
+ def self.[](contract_module)
3
+ new contract_module
4
+ end
5
+
6
+ def initialize(contract_module)
7
+ mod = contract_module
8
+
9
+ define_method(:contract_module) do
10
+ return contract_module
11
+ end
12
+
13
+ include contract_module
14
+ include Implementation
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ class DataContract < Module
2
+ module Implementation
3
+ def scatter(target)
4
+ setters.each do |setter|
5
+ getter = setter[0...-1]
6
+ val = send getter
7
+ target.send setter, val
8
+ end
9
+ end
10
+
11
+ def setters
12
+ contract_module.instance_methods(false).select { |m| m.to_s[-1, 1] == '=' }
13
+ end
14
+
15
+ def getters
16
+ contract_module.instance_methods(false).select { |m| m.to_s[-1, 1] != '=' }
17
+ end
18
+
19
+ def shared_contract?(other)
20
+ contract_module.instance_methods(false).each do |m|
21
+ return false unless other.respond_to? m
22
+ end
23
+ return true
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_contract
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - The Sans Collective
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/data_contract/data_contract.rb
20
+ - lib/data_contract/implementation.rb
21
+ - lib/data_contract.rb
22
+ homepage: https://github.com/Sans/data-contract
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Data Contract Library
45
+ test_files: []