lift 0.1.0

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: 1640a9179f3b77fdd19ac082678e61e4e8fec48a
4
+ data.tar.gz: 088f485db84eba7c7a378c53376a6fca071e988f
5
+ SHA512:
6
+ metadata.gz: b49dd78908a4c73f26bb6a7158ec8fe8fafc8277cd1a1d08ae2130d6b1606f41d344f6b51dca424a8a67c0606d8bab7b76dcfa120e9a15a0a90e305a72909a98
7
+ data.tar.gz: 9d8b15acd84dac16d543d8207a4de0b575d21548e03cd0f77e351aada37a93f8403cc73ab7f6ca4d6f6d24426035ac332a246e13cce522ea43986e4ecb0e3f33
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - "1.9.3"
3
+ - "2.0.0"
4
+ - "2.1.0"
5
+ - "jruby-19mode"
6
+ - "rbx-2"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lift.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ahawkins
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,51 @@
1
+ # Lift
2
+
3
+ [![Build Status](https://travis-ci.org/ahawkins/lift.svg)](https://travis-ci.org/ahawkins/lift)
4
+
5
+ Micro library for common pattern of initializing an object with a hash
6
+ and yielding itself to a block. This pattern is repeated widely across
7
+ the Ruby ecosystem. I duplicated this code across multiple projects
8
+ and eventually got sick of it so give you Lift!
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'lift'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install lift
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ class Person
28
+ include Lift
29
+
30
+ attr_accessor :name, :email
31
+ end
32
+
33
+ Person.new name: 'adam', email: 'example@example.com'
34
+
35
+ Person.new name: 'adam' do |adam|
36
+ adam.email = 'example@example.com'
37
+ end
38
+ ```
39
+
40
+ NOTE: Lift calls `super` with no arguments. This is so it can be used in
41
+ classes that include modules with their own `initialize` method. If an
42
+ ancestor's `initialize` method takes arguments then you should not use
43
+ this library.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/lift/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+ task default: :test
@@ -0,0 +1,11 @@
1
+ require "lift/version"
2
+
3
+ module Lift
4
+ def initialize(values = {})
5
+ super()
6
+ values.each_pair do |key, value|
7
+ send "#{key}=", value
8
+ end
9
+ yield self if block_given?
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Lift
2
+ VERSION = "0.1.0"
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 'lift/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lift"
8
+ spec.version = Lift::VERSION
9
+ spec.authors = ["ahawkins"]
10
+ spec.email = ["adam@hawkins.io"]
11
+ spec.summary = %q{Hash + Block initialization for easy object construction}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/ahawkins/lift"
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.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'test_helper'
2
+
3
+ class AcceptanceTest < MiniTest::Unit::TestCase
4
+ class Person
5
+ include Lift
6
+
7
+ attr_accessor :nick
8
+ end
9
+
10
+ module Gender
11
+ def initialize
12
+ @gender = :male
13
+ end
14
+
15
+ def gender
16
+ @gender
17
+ end
18
+ end
19
+
20
+ def test_sets_attributes
21
+ person = Person.new nick: 'ahawkins'
22
+ assert_equal 'ahawkins', person.nick
23
+ end
24
+
25
+ def test_works_with_a_block
26
+ person = Person.new do |person|
27
+ person.nick = 'ahawkins'
28
+ end
29
+
30
+ assert_equal 'ahawkins', person.nick
31
+ end
32
+
33
+ def test_super_is_called
34
+ klass = Class.new do
35
+ include Gender
36
+ include Lift
37
+ end
38
+
39
+ person = klass.new
40
+
41
+ assert_equal :male, person.gender
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler/setup'
2
+ require 'lift'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lift
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ahawkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - adam@hawkins.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/lift.rb
55
+ - lib/lift/version.rb
56
+ - lift.gemspec
57
+ - test/acceptance_test.rb
58
+ - test/test_helper.rb
59
+ homepage: https://github.com/ahawkins/lift
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Hash + Block initialization for easy object construction
83
+ test_files:
84
+ - test/acceptance_test.rb
85
+ - test/test_helper.rb