map-dem-tings 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f52a81b27d12d69b1a208d3531e1cba2a883e7e6
4
+ data.tar.gz: 37e6cfe1007aa82b31089b74d8b83afdd5c57e58
5
+ SHA512:
6
+ metadata.gz: 4631d8ffd65eb98e2c15f267fe7c66a6ee1c1b9d5a3cb7e814d1aaac55d611a2c50487d4dd88d23d3b31b8f347868024cd809135b2c585a06dea7ae46f888a2f
7
+ data.tar.gz: a032f7e8429f09d4cdb1ee205a90c2c024bbcd221ce399ee30951baedb44782443dde714ec79084da77b2fb8ac41cc77bc7188b9f834dd1e5e0a9783b7fc0ecc
@@ -0,0 +1,5 @@
1
+ /Gemfile.lock
2
+ /.ruby-gemset
3
+ /.ruby-version
4
+ /.rspec
5
+ /tmp/
@@ -0,0 +1 @@
1
+ map-dem-tings
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in map-dem-tings.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 baob
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.
@@ -0,0 +1,31 @@
1
+ # Map::Dem::Tings
2
+
3
+ Helps with repetitive mapping of inputs to outputs
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'map-dem-tings'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install map-dem-tings
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/baob/map-dem-tings/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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,67 @@
1
+ require "map-dem-tings/version"
2
+ require "map-dem-tings/input_mapper"
3
+
4
+ module MapDemTings
5
+ def self.included(base)
6
+ base.send :extend, ClassMethods
7
+ base.send :include, InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ # Example:
13
+ #
14
+ # define_mapping_methods(method_mapper: :mapper2,
15
+ # value_mapper: :mapper1,
16
+ # inputs: %w( atlas_id )
17
+ # )
18
+
19
+ def define_mapping_methods(opts)
20
+ method_mapper_sym = opts[:method_mapper]
21
+ value_mapper_sym = opts[:value_mapper]
22
+ inputs = opts[:inputs]
23
+
24
+ method_mapper = send(method_mapper_sym)
25
+
26
+ inputs.each do |input_name|
27
+ define_method(method_mapper.map(input_name)) do
28
+ send(value_mapper_sym).map(input_name)
29
+ end
30
+ end
31
+ end
32
+
33
+ def define_method_mapper(name, &block)
34
+ iv_name = "@@#{name}"
35
+
36
+ block_source_only = block.source.gsub("define_method_mapper(#{name.inspect})", '')
37
+
38
+ method_source = <<-end_src
39
+ def self.#{name}
40
+ #{iv_name} ||= MapDemTings::InputMapper.new #{block_source_only}
41
+ end
42
+ end_src
43
+
44
+ class_eval(method_source)
45
+ end
46
+
47
+ def define_value_mapper(name, &block)
48
+ iv_name = "@#{name}"
49
+
50
+ block_source_only = block.source.gsub("define_value_mapper(#{name.inspect})", '')
51
+
52
+ method_source = <<-end_src
53
+ def #{name}
54
+ #{iv_name} ||= MapDemTings::InputMapper.new #{block_source_only}
55
+ end
56
+ end_src
57
+
58
+ class_eval(method_source)
59
+ end
60
+
61
+ end
62
+
63
+ module InstanceMethods
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,34 @@
1
+ module MapDemTings
2
+ class InputMapper
3
+
4
+ # Simple mapper, can be used like a proc or lambda.
5
+ #
6
+ # Example
7
+ #
8
+ # def mapper
9
+ # @mapper ||= MapDemTings::InputMapper.new do |input|
10
+ # Array.wrap( wrap_params[input.to_s] )
11
+ # end
12
+ # end
13
+ #
14
+ # def author
15
+ # mapper.map(:author)
16
+ # end
17
+ #
18
+ # This simplifies methods below, but does not cut down
19
+ # on the number of repeats.
20
+ #
21
+ # def author
22
+ # Array.wrap( wrap_params["author"] )
23
+ # end
24
+
25
+ def initialize(&block)
26
+ @block = block
27
+ end
28
+
29
+ def map(name)
30
+ @block.call(name)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module MapDemTings
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'map-dem-tings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "map-dem-tings"
8
+ spec.version = MapDemTings::VERSION
9
+ spec.authors = ["baob"]
10
+ spec.email = ["coder@onesandthrees.com"]
11
+ spec.summary = %q{Helps with repetitive mapping of inputs to outputs}
12
+ spec.description = %q{Helps with repetitive mapping of inputs to outputs}
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map-dem-tings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - baob
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 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
+ description: Helps with repetitive mapping of inputs to outputs
42
+ email:
43
+ - coder@onesandthrees.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-gemset.example
50
+ - .ruby-version.example
51
+ - .travis.yml
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/map-dem-tings.rb
57
+ - lib/map-dem-tings/input_mapper.rb
58
+ - lib/map-dem-tings/version.rb
59
+ - map-dem-tings.gemspec
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.0
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Helps with repetitive mapping of inputs to outputs
84
+ test_files: []