laissez 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6b6bcec2c32b9c71f9b0adea68985e808239223
4
+ data.tar.gz: 1aa5e2300539f43568b6561f8a0502211164c21e
5
+ SHA512:
6
+ metadata.gz: 4ac86a6a5115f383f1297b1a2256d1ac6f3819051f959e58ae39fa6ce20e346a424cbea3af473d445527f6e629ec1eeb455a9744cd574eaf5696820926fb0e7e
7
+ data.tar.gz: 6464e3ce65ec753a2b8614dfaeac439be5fb3d0589d4db0947ea81b7fefd532dcdb7099c3099aeef311e4ca25fb0b356ab940fef0f98578e2c11e66076082939
data/.gitignore ADDED
@@ -0,0 +1,23 @@
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
23
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - jruby-18mode
5
+ - jruby-19mode
6
+ - rbx-2
7
+ - ruby-head
8
+ - jruby-head
9
+ - ree
10
+ notifications:
11
+ recipients:
12
+ - tech@printreleaf.com
13
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in laissez.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2014 PrintReleaf Inc.
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.
23
+
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Laissez
2
+
3
+ Lazy accessors, yo.
4
+
5
+ [![Build Status](https://travis-ci.org/PrintReleaf/laissez.png?branch=master)](https://travis-ci.org/PrintReleaf/laissez)
6
+
7
+
8
+ Adds `lazy_accessor`, `lazy_reader`, and `lazy_writer` to the Module class. Behaves just like its `attr_*` counterparts, except if the value is a Proc, the return value of calling the proc is returned instead.
9
+
10
+
11
+ ### Example:
12
+
13
+ ```ruby
14
+ class Person
15
+ lazy_accessor :name
16
+ end
17
+
18
+ person = Person.new
19
+ person.name # => nil
20
+ person.name = proc { "Ron Swanson" }
21
+ person.name # => "Ron Swanson"
22
+ ```
23
+
24
+ Additionally, you can pass a block to the getter instead, making the `=` unnecessary.
25
+
26
+ ```ruby
27
+ person.name { "Jean-Ralphio Saperstein" }
28
+ person.name # => "Jean-Ralphio Saperstein"
29
+ ```
30
+
31
+ ### Why would you want to use this?
32
+ - Lazy configuration
33
+ - Cheap DSLs
34
+ - Cheap method forwarding
35
+ - Defaults that might be destructive
36
+
37
+ ### Is this a good idea?
38
+ TBD.
39
+
40
+ ## Installation
41
+
42
+ Add this line to your application's Gemfile:
43
+
44
+ gem 'laissez'
45
+
46
+ And then execute:
47
+
48
+ $ bundle
49
+
50
+ Or install it yourself as:
51
+
52
+ $ gem install laissez
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/printreleaf/laissez/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
61
+
62
+ ### Run the tests
63
+
64
+ ```shell
65
+ $ rake test
66
+ ```
67
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
data/laissez.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'laissez/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "laissez"
8
+ spec.version = Laissez::VERSION
9
+ spec.authors = ["Casey O'Hara"]
10
+ spec.email = ["cohara@printreleaf.com"]
11
+ spec.summary = "Lazy accessors, yo."
12
+ spec.description = "Adds `lazy_accessor`, `lazy_reader`, and `lazy_writer` to the Module class.
13
+ Behaves just like its `attr_*` counterparts, except if the value is a Proc,
14
+ the return value of calling the proc is cached and returned instead."
15
+ spec.homepage = "https://github.com/printreleaf/laissez"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "minitest"
26
+ end
27
+
@@ -0,0 +1,3 @@
1
+ module Laissez
2
+ VERSION = "0.0.1"
3
+ end
data/lib/laissez.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "laissez/version"
2
+
3
+ class Module
4
+ def lazy_reader(*syms)
5
+ syms.map(&:to_s).each do |sym|
6
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
7
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
8
+ def #{sym}(&block)
9
+ return self.#{sym}=(block) if block_given?
10
+ #{sym} = @#{sym}
11
+ #{sym} = #{sym}.call if #{sym}.is_a? Proc
12
+ #{sym}
13
+ end
14
+ EOS
15
+ end
16
+ end
17
+
18
+ def lazy_writer(*syms)
19
+ syms.map(&:to_s).each do |sym|
20
+ raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
21
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
22
+ @#{sym} = nil unless defined? @#{sym}
23
+
24
+ def #{sym}=(obj)
25
+ @#{sym} = obj
26
+ end
27
+ EOS
28
+ end
29
+ end
30
+
31
+ def lazy_accessor(*syms, &blk)
32
+ lazy_reader(*syms, &blk)
33
+ lazy_writer(*syms, &blk)
34
+ end
35
+ end
36
+
@@ -0,0 +1,44 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'minitest/autorun'
5
+ require 'laissez'
6
+
7
+ describe "lazy_reader" do
8
+ class Image
9
+ lazy_reader :width, :height
10
+
11
+ def configure!
12
+ @width = proc { 1024 }
13
+ @height = proc { 576 }
14
+ end
15
+ end
16
+
17
+ it "returns the return value of calling the block" do
18
+ image = Image.new
19
+ image.configure!
20
+ image.width.must_equal 1024
21
+ image.height.must_equal 576
22
+ end
23
+ end
24
+
25
+ describe "lazy_accessor" do
26
+ class Box
27
+ lazy_accessor :width
28
+ lazy_accessor :height
29
+ lazy_accessor :length
30
+ end
31
+
32
+ it "returns the return value of calling the block" do
33
+ box = Box.new
34
+ box.width = proc { 1024 }
35
+ box.height = lambda { 576 }
36
+ box.length { 2048 }
37
+ box.width.must_equal 1024
38
+ box.height.must_equal 576
39
+ box.length.must_equal 2048
40
+ end
41
+ end
42
+
43
+
44
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laissez
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Casey O'Hara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-02 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
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |-
56
+ Adds `lazy_accessor`, `lazy_reader`, and `lazy_writer` to the Module class.
57
+ Behaves just like its `attr_*` counterparts, except if the value is a Proc,
58
+ the return value of calling the proc is cached and returned instead.
59
+ email:
60
+ - cohara@printreleaf.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - laissez.gemspec
72
+ - lib/laissez.rb
73
+ - lib/laissez/version.rb
74
+ - test/laissez_test.rb
75
+ homepage: https://github.com/printreleaf/laissez
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Lazy accessors, yo.
99
+ test_files:
100
+ - test/laissez_test.rb