usable 0.1.0

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: 97cce0168afce1846a0d35f692a9880e517dbe7e
4
+ data.tar.gz: 9fde115f8e348ef8fa94f9b79f231f1dce592026
5
+ SHA512:
6
+ metadata.gz: 3a19a138c0a0ddfb9a6c980cb4abaac2477f2458e95ca3a6a1bd07c6f6f6fcd1f5e53d5ce2e6c1ef08a14b3a065ce68bc817f12545a1bd59497587e39f0beab8
7
+ data.tar.gz: 6f8fd5859cdd1f1afac52db4555d374fc5cad64a578239358a7d6b2d4ff9eccc780281c314cf11c8324bfbbcde3367c27555dc7c14e8dfb7a1cb63deb653eda5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ usable
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in usable.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ryan Buckley
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Usable
2
+
3
+ Rack style mixins for Ruby objects. Mount your modules like you mean it!
4
+
5
+ ```ruby
6
+ class Model
7
+ extend Usable
8
+
9
+ module Versionable
10
+ def versions
11
+ "Saving #{self.class.config.max_versions} versions to #{self.class.config.table_name}"
12
+ end
13
+ end
14
+
15
+ # with options hash
16
+ use Versionable, table_name: 'custom_versions'
17
+
18
+ # or with block
19
+ use Versionable do |config|
20
+ config.max_versions = 10
21
+ end
22
+ end
23
+
24
+ Model.config.table_name #=> 'custom_versions'
25
+ Model.new.versions #=> "Saving 10 versions to custom_versions"
26
+ ```
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'usable'
34
+ ```
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install usable
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/usable.
49
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'rspec/scaffold'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "usable"
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
@@ -0,0 +1,58 @@
1
+ # @note UNTESTED and not included by default
2
+ module Usable
3
+ class Scoped
4
+ module Configurable
5
+ def configs
6
+ @configs ||= Hash.new do |me, key|
7
+ me[key] = Usable::Config.new
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.extended(base)
13
+ base.extend Configurable
14
+ end
15
+
16
+ def use(mod, options = {})
17
+ send :include, mod unless self < mod
18
+ if block_given?
19
+ yield configs[mod]
20
+ else
21
+ options.each { |k, v| configs[mod].public_send "#{k}=", v }
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ # but here's a example of how to use it
28
+ =begin
29
+ module Versionable
30
+ def versions
31
+ config = self.class.configs[Versionable]
32
+ "Saving #{config.max_versions} versions to #{config.table_name}"
33
+ end
34
+ end
35
+ module Notable
36
+ def notes
37
+ config = self.class.configs[Notable]
38
+ "Saving #{config.max_versions} notes to #{config.table_name}"
39
+ end
40
+ end
41
+ class Model
42
+ extend Usable::Scoped
43
+
44
+ # with options hash
45
+ use Versionable, table_name: 'custom_versions'
46
+ # or with block
47
+ use Versionable do |config|
48
+ config.max_versions = 10
49
+ end
50
+ use Notable do |config|
51
+ config.max_versions = 20
52
+ config.table_name = 'custom_notes'
53
+ end
54
+ end
55
+ Model.config.table_name #=> 'custom_versions'
56
+ Model.new.versions #=> "Saving 10 versions to custom_versions"
57
+ Model.new.notes #=> "Saving 20 notes to custom_notes"
58
+ =end
@@ -0,0 +1,3 @@
1
+ module Usable
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/usable.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "ostruct"
2
+ require "usable/version"
3
+
4
+ module Usable
5
+ def config
6
+ @config ||= Config.new
7
+ end
8
+
9
+ def use(mod, options = {})
10
+ send :include, mod unless self < mod
11
+ if block_given?
12
+ yield config
13
+ else
14
+ options.each { |k, v| config.public_send "#{k}=", v }
15
+ end
16
+ end
17
+
18
+ class Config < OpenStruct
19
+ end
20
+ end
data/usable.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'usable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "usable"
8
+ spec.version = Usable::VERSION
9
+ spec.authors = ["Ryan Buckley"]
10
+ spec.email = ["arebuckley@gmail.com"]
11
+
12
+ spec.summary = %q{Rack style mixins}
13
+ spec.description = %q{Rack style mixins which provide a convention for passing options to your modules.}
14
+ spec.homepage = "https://github.com/ridiculous/usable"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '>= 3.2', '< 4'
24
+ spec.add_development_dependency 'rspec-scaffold', '>= 1.0', '< 2'
25
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Buckley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-30 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '4'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.2'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-scaffold
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '2'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '1.0'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '2'
81
+ description: Rack style mixins which provide a convention for passing options to your
82
+ modules.
83
+ email:
84
+ - arebuckley@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".ruby-gemset"
91
+ - ".ruby-version"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.md
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/usable.rb
100
+ - lib/usable/scoped.rb
101
+ - lib/usable/version.rb
102
+ - usable.gemspec
103
+ homepage: https://github.com/ridiculous/usable
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Rack style mixins
126
+ test_files: []