poro_properties 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/poro_properties.rb +28 -0
- data/lib/poro_properties/defaults.rb +18 -0
- data/lib/poro_properties/version.rb +3 -0
- data/poro_properties.gemspec +25 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2d44d40d5f3ed90cb8c59362275da8d5a708eaa
|
4
|
+
data.tar.gz: a360264fbc8ae6262a9e50f2a77112ce34a11a94
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20e3bed557febedb9ce3c888224f1768e06bce1dd70b0161f6976846a7d2aa609279d9bf30e9f0a75a7b9b67c6529e259fee22367c0ff50811fe39cfd638080d
|
7
|
+
data.tar.gz: 6b7e4ae0e7797f85ee3b230e5d71cb774872b7c2ccd7c70c80ae33360f0452030b75d18f148c537d24bdbfdf8ed88f0bc86c6e3e936e3b5d3b44c779be0e0ebd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Lenon Marcel
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# PoroProperties
|
2
|
+
[![Build Status][ci-image]][ci]
|
3
|
+
[![Code Climate][cc-image]][cc]
|
4
|
+
|
5
|
+
Allows you to define properties on your Ruby classes.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'poro_properties'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install poro_properties
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You must require 'poro_properties' and then include it on your class:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'poro_properties'
|
29
|
+
|
30
|
+
class MyClass
|
31
|
+
include PoroProperties
|
32
|
+
|
33
|
+
properties :foo, :bar
|
34
|
+
property :baz
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
When you include PoroProperties, the following methods are available on your
|
39
|
+
class:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
MyClass.properties_names
|
43
|
+
MyClass.new.to_h
|
44
|
+
```
|
45
|
+
|
46
|
+
You can also pass default values:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'poro_properties/defaults'
|
50
|
+
|
51
|
+
class MyClass
|
52
|
+
include PoroProperties
|
53
|
+
include PoroProperties::Defaults
|
54
|
+
|
55
|
+
property :foo, default: 'bar'
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
62
|
+
`bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
65
|
+
release a new version, update the version number in `version.rb`, and then run
|
66
|
+
`bundle exec rake release` to create a git tag for the version, push git commits
|
67
|
+
and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it ( https://github.com/estoulendo/poro_properties/fork )
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create a new Pull Request
|
76
|
+
|
77
|
+
[ci-image]:https://travis-ci.org/estoulendo/poro_properties.svg?branch=master
|
78
|
+
[ci]:https://travis-ci.org/estoulendo/poro_properties
|
79
|
+
[cc-image]:https://codeclimate.com/github/estoulendo/poro_properties/badges/gpa.svg
|
80
|
+
[cc]:https://codeclimate.com/github/estoulendo/poro_properties
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "poro_properties"
|
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,28 @@
|
|
1
|
+
require 'poro_properties/version'
|
2
|
+
|
3
|
+
module PoroProperties
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_h
|
9
|
+
self.class.properties_names
|
10
|
+
.inject({}) { |memo, key| memo.merge(key => public_send(key)) }
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
attr_accessor :properties_names
|
15
|
+
|
16
|
+
def properties(*names)
|
17
|
+
attr_accessor(*names)
|
18
|
+
@properties_names ||= []
|
19
|
+
@properties_names += names
|
20
|
+
end
|
21
|
+
|
22
|
+
def property(name)
|
23
|
+
attr_accessor(name)
|
24
|
+
@properties_names ||= []
|
25
|
+
@properties_names << name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PoroProperties
|
2
|
+
module Defaults
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_accessor :properties_defaults
|
9
|
+
|
10
|
+
def property(name, default:)
|
11
|
+
super(name)
|
12
|
+
define_method(name) do
|
13
|
+
instance_variable_get("@#{name}") || default
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -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 'poro_properties/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'poro_properties'
|
8
|
+
spec.version = PoroProperties::VERSION
|
9
|
+
spec.authors = ['Lenon Marcel']
|
10
|
+
spec.email = ['lenon.marcel@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Allows you to define properties on Ruby classes.'
|
13
|
+
spec.description = 'Allows you to define properties on Ruby classes.'
|
14
|
+
spec.homepage = 'https://github.com/estoulendo/poro_properties'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poro_properties
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lenon Marcel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-28 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
|
+
- !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: 3.2.0
|
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: 3.2.0
|
61
|
+
description: Allows you to define properties on Ruby classes.
|
62
|
+
email:
|
63
|
+
- lenon.marcel@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- ".travis.yml"
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/console
|
76
|
+
- bin/setup
|
77
|
+
- lib/poro_properties.rb
|
78
|
+
- lib/poro_properties/defaults.rb
|
79
|
+
- lib/poro_properties/version.rb
|
80
|
+
- poro_properties.gemspec
|
81
|
+
homepage: https://github.com/estoulendo/poro_properties
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Allows you to define properties on Ruby classes.
|
105
|
+
test_files: []
|