plaster 0.1.0.pre.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGQ5MThmYjczNzZkOGRkYjJmYTgzNDU1ZTFlNWQ4MThhNWQ1ZjQwOA==
5
+ data.tar.gz: !binary |-
6
+ OGQyYTQ4OGVmZTliN2E2ZjlmN2IxYTBmMzAyOWUyMjk4MjBiMzQ5Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YjI4YThmZTNjNTAyNmJjNzBkNzMwZjdlOTI5N2QwMWQxZjhlODI5ODY0ZmRi
10
+ OTE0MzFiNDZmNDU4ODhjNGVlOWFjMWM2MDhlZDg5YzIzZDcwYWQ4Y2UwOTlj
11
+ MWNjOGJlMmVlZDU4OGJjMTViNThmMDAzZGIzMTg2M2I0ZDhmNGI=
12
+ data.tar.gz: !binary |-
13
+ MzNiMTNkZWE4OTQ3NGY3OTQ5OWEwNzg4ZTUxNDdlYzgxZWM1N2ZkN2NhY2Jl
14
+ Y2RkY2I3NzY2ODk4NjdlODEyMGY1MzYyM2E0YTQzZjg4NTFhMzVhYzZlZjhk
15
+ OTY0YTE3M2IwNjg2NDY1NDAzMGIzNTg5MGVlM2U1N2FmMGFhNGQ=
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,28 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all
4
+ people who contribute through reporting issues, posting feature requests,
5
+ updating documentation, submitting pull requests or patches, and other
6
+ activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, or religion.
12
+
13
+ Examples of unacceptable behavior by participants include the use of sexual
14
+ language or imagery, derogatory comments or personal attacks, trolling, public
15
+ or private harassment, insults, or other unprofessional conduct.
16
+
17
+ Project maintainers have the right and responsibility to remove, edit, or
18
+ reject comments, commits, code, wiki edits, issues, and other contributions
19
+ that are not aligned to this Code of Conduct. Project maintainers who do not
20
+ follow the Code of Conduct may be removed from the project team.
21
+
22
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
23
+ reported by opening an issue or contacting one or more of the project
24
+ maintainers.
25
+
26
+ This Code of Conduct is adapted from the [Contributor
27
+ Covenant](http://contributor-covenant.org), version 1.0.0, available at
28
+ [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in plaster.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Steve Jorgensen
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Plaster
2
+
3
+ A toolkit to aid in the convertsion of complex data into or out of a
4
+ concretely modeled structure for purposes of transport between software
5
+ systems or components.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby gem 'plaster' ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install plaster
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
28
+ `rake rspec` to run the tests. You can also run `bin/console` for an
29
+ interactive prompt that will allow you to experiment. Run `bundle exec plaster`
30
+ to use the gem in this directory, ignoring other installed copies of this gem.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To
33
+ release a new version, update the version number in `version.rb`, and then run
34
+ `bundle exec rake release`, which will create a git tag for the version, push
35
+ git commits and tags, and push the `.gem` file to
36
+ [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at
41
+ https://github.com/[USERNAME]/plaster. This project is intended to be a safe,
42
+ welcoming space for collaboration, and contributors are expected to adhere to
43
+ the [Contributor Covenant](contributor-covenant.org) code of conduct.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT
49
+ License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plaster"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/plaster ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "plaster"
@@ -0,0 +1,96 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+
3
+ module Plaster
4
+
5
+ class ModelDeconstructor
6
+
7
+ class << self
8
+ extend Forwardable
9
+
10
+ def_delegator :default_instance, :call
11
+
12
+ def default_instance
13
+ @default_instance ||= new
14
+ end
15
+ end
16
+
17
+ def self.default_instance
18
+ @default_instance ||= new
19
+ end
20
+
21
+ def call(obj)
22
+ if obj.respond_to?( :model_deconstruct )
23
+ obj.model_deconstruct
24
+ elsif obj.respond_to?( :to_hash )
25
+ deconstruct_from_hash( obj )
26
+ elsif bag_like?( obj )
27
+ deconstruct_from_bag_like( obj )
28
+ elsif hash_like?( obj )
29
+ deconstruct_from_hash_like( obj )
30
+ elsif map_like?( obj )
31
+ deconstruct_from_map_like( obj )
32
+ else
33
+ obj
34
+ end
35
+ end
36
+
37
+ def bag_like?(obj)
38
+ return true if \
39
+ obj.respond_to?( :to_ary )
40
+
41
+ return false if \
42
+ obj.respond_to?( :to_hash )
43
+
44
+ obj.respond_to?( :to_a ) &&
45
+ obj.respond_to?( :each ) &&
46
+ obj.respond_to?( :map ) &&
47
+ obj.respond_to?( :& ) &&
48
+ obj.respond_to?( :| ) &&
49
+ obj.respond_to?( :+ ) &&
50
+ obj.respond_to?( :- )
51
+ end
52
+
53
+ def hash_like?(obj)
54
+ obj.respond_to?( :to_h ) &&
55
+ obj.respond_to?( :each_pair )
56
+ end
57
+
58
+ def map_like?(obj)
59
+ obj.respond_to?( :each_pair ) &&
60
+ obj.respond_to?( :values ) &&
61
+ obj.respond_to?( :[] )
62
+ end
63
+
64
+ def deconstruct_from_hash(hash)
65
+ hash = HashWIA.new( hash.to_hash )
66
+ deconstruct_hash_values!( hash )
67
+ end
68
+
69
+ def deconstruct_from_bag_like(obj)
70
+ obj.map { |entry|
71
+ call( entry )
72
+ }
73
+ end
74
+
75
+ def deconstruct_from_hash_like(obj)
76
+ hash = obj.to_h
77
+ deconstruct_hash_values!( hash )
78
+ end
79
+
80
+ def deconstruct_from_map_like(obj)
81
+ hash = HashWIA.new.tap do |h|
82
+ obj.each_pair do |k,v| ; h[k] = v ; end
83
+ end
84
+ deconstruct_hash_values!( hash )
85
+ end
86
+
87
+ def deconstruct_hash_values!(hash)
88
+ hash.each_pair do |k,v|
89
+ dv = call( v )
90
+ hash[k] = dv unless dv.equal?( v )
91
+ end
92
+ hash
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,3 @@
1
+ module Plaster
2
+ VERSION = "0.1.0-pre"
3
+ end
@@ -0,0 +1,69 @@
1
+ module Plaster
2
+
3
+ class WrappingList
4
+
5
+ class << self
6
+ attr_reader :wrapper_class, :wrapper_attrib
7
+
8
+ def wrapper_attrib_writer
9
+ @wrapper_attrib_writer ||= :"#{wrapper_attrib}="
10
+ end
11
+
12
+ private
13
+
14
+ def wrap_each(klass, attrib)
15
+ @wrapper_class = klass
16
+ @wrapper_attrib = attrib
17
+ end
18
+ end
19
+
20
+ include Enumerable
21
+
22
+ attr_reader :inner_array
23
+
24
+ def initialize
25
+ @inner_array = []
26
+ end
27
+
28
+ def []=(index, value)
29
+ old_length = inner_array.length
30
+ wrapper = (
31
+ inner_array[index] ||= self.class.wrapper_class.new
32
+ )
33
+ wrapper.send self.class.wrapper_attrib_writer, value
34
+ if index > old_length
35
+ (old_length...index).each do |fill_idx|
36
+ inner_array[fill_idx] = self.class.wrapper_class.new
37
+ end
38
+ end
39
+ value
40
+ end
41
+
42
+ def [](index)
43
+ wrapper = inner_array[index]
44
+ wrapper.send self.class.wrapper_attrib
45
+ end
46
+
47
+ def each
48
+ return Enumerator.new(self, :each) unless block_given?
49
+ inner_array.each do |wrapper|
50
+ value = wrapper.send(self.class.wrapper_attrib)
51
+ yield value
52
+ end
53
+ end
54
+
55
+ def <<(value)
56
+ wrapper = self.class.wrapper_class.new
57
+ wrapper.send self.class.wrapper_attrib_writer, value
58
+ inner_array << wrapper
59
+ end
60
+
61
+ def push(*values)
62
+ values.each do |value|
63
+ self << value
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ end
data/lib/plaster.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "plaster/version"
2
+ require "plaster/model_deconstructor"
3
+ require "plaster/wrapping_list"
4
+
5
+ module Plaster
6
+ HashWIA = ::HashWithIndifferentAccess
7
+
8
+ extend (
9
+ module SingletonBehavior ; self ; end
10
+ )
11
+
12
+ module SingletonBehavior
13
+ def deconstruct(obj)
14
+ ModelDeconstructor.call(obj)
15
+ end
16
+
17
+ def []()
18
+ WrappingList
19
+ end
20
+ end
21
+
22
+ end
data/plaster.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'plaster/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "plaster"
8
+ spec.version = Plaster::VERSION
9
+ spec.authors = ["Steve Jorgensen"]
10
+ spec.email = ["stevej@stevej.name"]
11
+
12
+ spec.summary = "Aids conversion of data into or out a concretely modeled " \
13
+ "structure for transport between software systems or " \
14
+ "components."
15
+ spec.homepage = "https://github.com/stevecj/plaster"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = ">= 1.9.3"
24
+
25
+ spec.add_dependency "activesupport", ">= 2.3"#, require: 'active_support/hash_with_indifferent_access'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "virtus", "~> 1.0.5"
31
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.pre
5
+ platform: ruby
6
+ authors:
7
+ - Steve Jorgensen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: virtus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.5
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.5
83
+ description:
84
+ email:
85
+ - stevej@stevej.name
86
+ executables:
87
+ - plaster
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .ruby-version
94
+ - .travis.yml
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - exe/plaster
103
+ - lib/plaster.rb
104
+ - lib/plaster/model_deconstructor.rb
105
+ - lib/plaster/version.rb
106
+ - lib/plaster/wrapping_list.rb
107
+ - plaster.gemspec
108
+ homepage: https://github.com/stevecj/plaster
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 1.9.3
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ! '>'
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Aids conversion of data into or out a concretely modeled structure for transport
132
+ between software systems or components.
133
+ test_files: []