procto-0.0.3/0000755000175200017520000000000013631717224012260 5ustar debiandebianprocto-0.0.3/spec/0000755000175200017520000000000013631717224013212 5ustar debiandebianprocto-0.0.3/spec/unit/0000755000175200017520000000000013631717224014171 5ustar debiandebianprocto-0.0.3/spec/unit/procto/0000755000175200017520000000000013631717224015477 5ustar debiandebianprocto-0.0.3/spec/unit/procto/to_proc_spec.rb0000644000175200017520000000064713631717224020512 0ustar debiandebian# encoding: utf-8 require 'spec_helper' describe Procto, '.to_proc' do include_context 'procto' subject { proc.call(text) } let(:proc) { klass.to_proc } let(:klass) do Class.new do include Procto.call def initialize(text) @text = text end def call "Hello #{@text}" end end end it 'exposes a lambda proc' do expect(proc).to be_a_lambda end end procto-0.0.3/spec/unit/procto/call_spec.rb0000644000175200017520000000134013631717224017747 0ustar debiandebian# encoding: utf-8 require 'spec_helper' describe Procto, '.call' do subject { klass.call(text) } context 'with no name' do include_context 'procto' let(:klass) do Class.new do include Procto.call def initialize(text) @text = text end def call "Hello #{@text}" end end end end context 'with a name' do include_context 'procto' let(:name) { double('name', to_sym: :print) } let(:klass) do method_name = name Class.new do include Procto.call(method_name) def initialize(text) @text = text end def print "Hello #{@text}" end end end end end procto-0.0.3/spec/spec_helper.rb0000644000175200017520000000112013631717224016022 0ustar debiandebian# encoding: utf-8 if ENV['COVERAGE'] == 'true' require 'simplecov' require 'coveralls' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] SimpleCov.start do command_name 'spec:unit' add_filter 'config' add_filter 'spec' minimum_coverage 100 end end require 'procto' require 'devtools/spec_helper' RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = :expect end config.mock_with :rspec do |c| c.syntax = :expect end end procto-0.0.3/spec/shared/0000755000175200017520000000000013631717224014460 5ustar debiandebianprocto-0.0.3/spec/shared/procto_behavior.rb0000644000175200017520000000030413631717224020167 0ustar debiandebian# encoding: utf-8 shared_context 'procto' do let(:text) { 'world' } let(:expected) { "Hello #{text}" } it 'returns the correct value' do expect(subject).to eql(expected) end end procto-0.0.3/procto.gemspec0000644000175200017520000000141213631717224015131 0ustar debiandebian# encoding: utf-8 require File.expand_path('../lib/procto/version', __FILE__) Gem::Specification.new do |gem| gem.name = "procto" gem.version = Procto::VERSION.dup gem.authors = [ 'Martin Gamsjaeger (snusnu)' ] gem.email = [ 'gamsnjaga@gmail.com' ] gem.description = 'Turns your object into a method object' gem.summary = 'Defines Foo.call(*args) which invokes Foo.new(*args).bar ' gem.homepage = 'https://github.com/snusnu/procto' gem.require_paths = [ 'lib' ] gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {spec}/*`.split("\n") gem.extra_rdoc_files = %w[LICENSE README.md CONTRIBUTING.md] gem.license = 'MIT' gem.add_development_dependency 'bundler', '~> 1' end procto-0.0.3/lib/0000755000175200017520000000000013631717224013026 5ustar debiandebianprocto-0.0.3/lib/procto/0000755000175200017520000000000013631717224014334 5ustar debiandebianprocto-0.0.3/lib/procto/version.rb0000644000175200017520000000013013631717224016340 0ustar debiandebian# encoding: utf-8 class Procto < Module # Gem version VERSION = '0.0.3'.freeze end procto-0.0.3/lib/procto.rb0000644000175200017520000000416313631717224014665 0ustar debiandebian# encoding: utf-8 class Procto < Module # The default name of the instance method to be called DEFAULT_NAME = :call private_class_method :new # Return a module that turns the host into a method object # # @example without a name # # class Greeter # include Procto.call # # def initialize(text) # @text = text # end # # def call # "Hello #{text}" # end # end # # Greeter.call('world') # => "Hello world" # # @example with a name # # class Printer # include Procto.call(:print) # # def initialize(text) # @text = text # end # # def print # "Hello #{text}" # end # end # # Printer.call('world') # => "Hello world" # # @param [#to_sym] name # the name of the instance method to call # # @return [Procto] # # @api public def self.call(name = DEFAULT_NAME) new(name.to_sym) end # Initialize a new instance # # @param [Symbol] name # the name of the instance method to call # # @return [undefined] # # @api private def initialize(name) @block = ->(*args) { new(*args).public_send(name) } end private # Define the .call method on +host+ # # @param [Object] host # the hosting object # # @return [undefined] # # @api private def included(host) host.instance_exec(@block) do |block| define_singleton_method(:call, &block) end host.extend(ClassMethods) end # Procto module for adding .to_proc to host class module ClassMethods # Return the `call` singleton method as a lambda # # @example using a class as a proc # # class Shouter # include Procto.call # # def initialize(text) # @text = text # end # # def call # "#{@text.upcase}!" # end # end # # Shouter.to_proc.call('hello') # => "HELLO!" # %w[foo bar].map(&Shouter) # => ["FOO!", "BAR!"] # # @return [Proc] # # @api public def to_proc public_method(:call).to_proc end end private_constant(:ClassMethods) end # Procto procto-0.0.3/config/0000755000175200017520000000000013631717224013525 5ustar debiandebianprocto-0.0.3/config/yardstick.yml0000644000175200017520000000002313631717224016240 0ustar debiandebian--- threshold: 100 procto-0.0.3/config/rubocop.yml0000644000175200017520000000353613631717224015730 0ustar debiandebianAllCops: Include: - '**/*.rake' - 'Gemfile' - 'Gemfile.devtools' Exclude: - '**/vendor/**' - '**/benchmarks/**' # Avoid parameter lists longer than five parameters. ParameterLists: Max: 1 CountKeywordArgs: true # Avoid more than `Max` levels of nesting. BlockNesting: Max: 1 # Align with the style guide. CollectionMethods: PreferredMethods: collect: 'map' inject: 'reduce' find: 'detect' find_all: 'select' # Do not force public/protected/private keyword to be indented at the same # level as the def keyword. My personal preference is to outdent these keywords # because I think when scanning code it makes it easier to identify the # sections of code and visually separate them. When the keyword is at the same # level I think it sort of blends in with the def keywords and makes it harder # to scan the code and see where the sections are. AccessModifierIndentation: Enabled: false # Limit line length LineLength: Max: 80 # Disable documentation checking until a class needs to be documented once Documentation: Enabled: false # Do not favor modifier if/unless usage when you have a single-line body IfUnlessModifier: Enabled: false # Allow case equality operator (in limited use within the specs) CaseEquality: Enabled: false # Constants do not always have to use SCREAMING_SNAKE_CASE ConstantName: Enabled: false # Not all trivial readers/writers can be defined with attr_* methods TrivialAccessors: Enabled: false # Do not favor aligned parameters in method calls AlignParameters: Enabled: false HashSyntax: Enabled: false SpaceInsideBrackets: Enabled: false Lambda: Enabled: false # i personally like the look of multiline ->(arg) {} lambdas AndOr: Enabled: false # we agree to use and/or for control flow # Allow code to be aligned more nicely SpaceBeforeFirstArg: Enabled: false procto-0.0.3/config/reek.yml0000644000175200017520000000335013631717224015177 0ustar debiandebian--- Attribute: enabled: true exclude: [] BooleanParameter: enabled: true exclude: [] ClassVariable: enabled: true exclude: [] ControlParameter: enabled: true exclude: [] DataClump: enabled: true exclude: [] max_copies: 2 min_clump_size: 2 DuplicateMethodCall: enabled: true exclude: [] max_calls: 1 allow_calls: [] FeatureEnvy: enabled: true exclude: [] IrresponsibleModule: enabled: false exclude: [] LongParameterList: enabled: true exclude: [] max_params: 1 overrides: initialize: max_params: 2 LongYieldList: enabled: true exclude: [] max_params: 1 NestedIterators: enabled: true exclude: - Lupo#included # 2 max_allowed_nesting: 1 ignore_iterators: [] NilCheck: enabled: true exclude: [] RepeatedConditional: enabled: true exclude: [] max_ifs: 1 TooManyInstanceVariables: enabled: true exclude: [] max_instance_variables: 1 TooManyMethods: enabled: true exclude: [] max_methods: 3 TooManyStatements: enabled: true exclude: [] max_statements: 4 UncommunicativeMethodName: enabled: true exclude: [] reject: - !ruby/regexp /^[a-z]$/ - !ruby/regexp /[0-9]$/ - !ruby/regexp /[A-Z]/ accept: [] UncommunicativeModuleName: enabled: true exclude: [] reject: - !ruby/regexp /^.$/ - !ruby/regexp /[0-9]$/ accept: [] UncommunicativeParameterName: enabled: true exclude: [] reject: - !ruby/regexp /^.$/ - !ruby/regexp /[0-9]$/ - !ruby/regexp /[A-Z]/ accept: [] UncommunicativeVariableName: enabled: true exclude: [] reject: - !ruby/regexp /^.$/ - !ruby/regexp /[0-9]$/ - !ruby/regexp /[A-Z]/ accept: [] UnusedParameters: enabled: true exclude: [] UtilityFunction: enabled: true exclude: [] max_helper_calls: 0 procto-0.0.3/config/mutant.yml0000644000175200017520000000004313631717224015555 0ustar debiandebian--- name: procto namespace: Procto procto-0.0.3/config/flog.yml0000644000175200017520000000002313631717224015172 0ustar debiandebian--- threshold: 5.5 procto-0.0.3/config/flay.yml0000644000175200017520000000004013631717224015175 0ustar debiandebian--- threshold: 2 total_score: 2 procto-0.0.3/config/devtools.yml0000644000175200017520000000003313631717224016103 0ustar debiandebian--- unit_test_timeout: 0.1 procto-0.0.3/Rakefile0000644000175200017520000000011713631717224013724 0ustar debiandebian# encoding: utf-8 require 'rake' require 'devtools' Devtools.init_rake_tasks procto-0.0.3/README.md0000644000175200017520000000242013631717224013535 0ustar debiandebian# procto [![Gem Version](https://badge.fury.io/rb/procto.png)][gem] [![Build Status](https://secure.travis-ci.org/snusnu/procto.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/snusnu/procto.png)][gemnasium] [![Code Climate](https://codeclimate.com/github/snusnu/procto.png)][codeclimate] [![Coverage Status](https://coveralls.io/repos/snusnu/procto/badge.png?branch=master)][coveralls] [gem]: https://rubygems.org/gems/procto [travis]: https://travis-ci.org/snusnu/procto [gemnasium]: https://gemnasium.com/snusnu/procto [codeclimate]: https://codeclimate.com/github/snusnu/procto [coveralls]: https://coveralls.io/r/snusnu/procto ## Usage ```ruby require 'procto' class Greeter include Procto.call def initialize(text) @text = text end def call "Hello #{text}" end end Greeter.call('world') # => "Hello world" class Printer include Procto.call(:print) def initialize(text) @text = text end def print "Hello #{text}" end end Printer.call('world') # => "Hello world" ``` ## Credits * [snusnu](https://github.com/snusnu) * [mbj](https://github.com/mbj) ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) for details. ## Copyright Copyright © 2013 Martin Gamsjaeger (snusnu). See [LICENSE](LICENSE) for details. procto-0.0.3/LICENSE0000644000175200017520000000205613631717224013270 0ustar debiandebianCopyright (c) 2013 Martin Gamsjaeger (snusnu) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. procto-0.0.3/Gemfile0000644000175200017520000000030413631717224013550 0ustar debiandebian# encoding: utf-8 source 'https://rubygems.org' gemspec group :development do gem 'devtools', git: 'https://github.com/mbj/devtools.git' end group :test do gem 'coveralls', '~> 0.8.9' end procto-0.0.3/CONTRIBUTING.md0000644000175200017520000000142613631717224014514 0ustar debiandebianContributing ------------ * If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. * Fork the project. * Make your feature addition or bug fix. * Follow this [style guide](https://github.com/dkubb/styleguide). * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered. * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) * Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged. * Send me a pull request. Bonus points for topic branches. procto-0.0.3/.travis.yml0000644000175200017520000000063213631717224014372 0ustar debiandebianlanguage: ruby before_install: gem install bundler bundler_args: --without yard guard benchmarks script: "bundle exec rake ci" rvm: - 2.3.0 - ruby-head - rbx-19mode matrix: include: - rvm: jruby-19mode env: JRUBY_OPTS="$JRUBY_OPTS --debug" - rvm: jruby-head env: JRUBY_OPTS="$JRUBY_OPTS --debug" allow_failures: - rvm: rbx-19mode - rvm: jruby-19mode - rvm: jruby-head procto-0.0.3/.ruby-gemset0000644000175200017520000000000713631717224014521 0ustar debiandebianprocto procto-0.0.3/.rspec0000644000175200017520000000006313631717224013374 0ustar debiandebian--color --profile --order random --format progress procto-0.0.3/.gitignore0000644000175200017520000000040713631717224014251 0ustar debiandebian## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## Rubinius *.rbc .rbx ## PROJECT::GENERAL *.gem coverage profiling turbulence rdoc pkg tmp doc log .yardoc measurements ## BUNDLER .bundle Gemfile.lock ## PROJECT::SPECIFIC