creatable 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 805d90e2b323e067b44514cc1e02e3b5fabefea5
4
- data.tar.gz: ec25cda1fd8eea6c79d31afba436df330612e5de
3
+ metadata.gz: 9486fdf6f7b16f7f47017d42137d18fe6122d709
4
+ data.tar.gz: 3e2a51254d9e8c10444c70e7910b80e90e6a20f8
5
5
  SHA512:
6
- metadata.gz: e88e6ee823bdc849aeb1b2799c7f4fa3a60c1f7220d7e45efcaa85afa1187b4d95cec3b77474ae3e1b1e5341aad22cd235f55a89097c6bd102bee3ded166e2ca
7
- data.tar.gz: a9478111114dd34d92890be5ba17c1a6ff9a9b223b41c0a9e753b8e8d94a73af921774988977f79a4da8ca222461bbea056fe2e99c1aa4e7af1903e37857f12e
6
+ metadata.gz: c0ffc433467fea9f018fca7feb88b11a57872bf753d643b5539101df7a694130f95e33cccf32e09e96bddad3c2815c06b950560ec8ecbb4a0e7ce5c149428602
7
+ data.tar.gz: 1b31eae388bcc13cb19848daf15d27bd3a1bee59f624d79b7380983c188525bef89937060b572ca5e6c21f11c04d9844a62a9e021529a787b0d30245dd1bbc02
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+
5
+ ---
6
+
7
+ **Is your feature request related to a problem? Please describe.**
8
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9
+
10
+ **Describe the solution you'd like**
11
+ A clear and concise description of what you want to happen.
12
+
13
+ **Describe alternatives you've considered**
14
+ A clear and concise description of any alternative solutions or features you've considered.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,13 @@
1
+ before_script:
2
+ - ruby -v
3
+ - which ruby
4
+ - gem install bundler --no-ri --no-rdoc
5
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
6
+
7
+ rspec:
8
+ script:
9
+ - bundle exec rspec
10
+
11
+ rubocop:
12
+ script:
13
+ - bundle exec rubocop
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ebrodeur@ujami.net. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
data/Guardfile CHANGED
@@ -1,19 +1,4 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- ## Uncomment and set this to only include directories you want to watch
5
- # directories %w(app lib config test spec features) \
6
- # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
-
8
- ## Note: if you are using the `directories` clause above and you are not
9
- ## watching the project directory ('.'), then you will want to move
10
- ## the Guardfile to a watched dir and symlink it back, e.g.
11
- #
12
- # $ mkdir config
13
- # $ mv Guardfile config/
14
- # $ ln -s config/Guardfile .
15
- #
16
- # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
1
+ clearing :on
17
2
 
18
3
  guard :bundler do
19
4
  require 'guard/bundler'
@@ -27,21 +12,10 @@ guard :bundler do
27
12
  files.each { |file| watch(helper.real_path(file)) }
28
13
  end
29
14
 
30
- # Note: The cmd option is now required due to the increasing number of ways
31
- # rspec may be run, below are examples of the most common uses.
32
- # * bundler: 'bundle exec rspec'
33
- # * bundler binstubs: 'bin/rspec'
34
- # * spring: 'bin/rspec' (This will use spring if running and you have
35
- # installed the spring binstubs per the docs)
36
- # * zeus: 'zeus rspec' (requires the server to be started separately)
37
- # * 'just' rspec: 'rspec'
38
-
39
15
  guard :rspec, cmd: 'bundle exec rspec' do
40
16
  require 'guard/rspec/dsl'
41
17
  dsl = Guard::RSpec::Dsl.new(self)
42
18
 
43
- # Feel free to open issues for suggestions and improvements
44
-
45
19
  # RSpec files
46
20
  rspec = dsl.rspec
47
21
  watch(rspec.spec_helper) { rspec.spec_dir }
@@ -51,34 +25,6 @@ guard :rspec, cmd: 'bundle exec rspec' do
51
25
  # Ruby files
52
26
  ruby = dsl.ruby
53
27
  dsl.watch_spec_files_for(ruby.lib_files)
54
-
55
- # Rails files
56
- rails = dsl.rails(view_extensions: ['erb', 'haml', 'slim'])
57
- dsl.watch_spec_files_for(rails.app_files)
58
- dsl.watch_spec_files_for(rails.views)
59
-
60
- watch(rails.controllers) do |m|
61
- [
62
- rspec.spec.call("routing/#{m[1]}_routing"),
63
- rspec.spec.call("controllers/#{m[1]}_controller"),
64
- rspec.spec.call("acceptance/#{m[1]}")
65
- ]
66
- end
67
-
68
- # Rails config changes
69
- watch(rails.spec_helper) { rspec.spec_dir }
70
- watch(rails.routes) { "#{rspec.spec_dir}/routing" }
71
- watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
72
-
73
- # Capybara features specs
74
- watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
75
- watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
76
-
77
- # Turnip features and steps
78
- watch(%r{^spec/acceptance/(.+)\.feature$})
79
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
80
- Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
81
- end
82
28
  end
83
29
 
84
30
  unless ENV["DISABLE_RUBOCOP"] == 'true'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ernie Brodeur
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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Creatable
2
2
 
3
+ [![CodeFactor](https://www.codefactor.io/repository/github/erniebrodeur/creatable/badge)](https://www.codefactor.io/repository/github/erniebrodeur/creatable)
4
+
3
5
  A mixin that adds a `create` method to any class.
4
6
 
5
7
  ## Installation
@@ -12,11 +14,11 @@ gem 'creatable'
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ bundle
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install creatable
21
+ gem install creatable
20
22
 
21
23
  ## Usage
22
24
 
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-midnight
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'creatable/version'
@@ -1,42 +1,18 @@
1
1
  require "creatable/version"
2
+ require 'creatable/class_methods'
2
3
 
3
- # include this, documentation will come.
4
+ # Main module you include in your class
4
5
  module Creatable
5
- def attributes
6
- @attributes ||= []
7
- @attributes
6
+ # Override to load the ClassMethods
7
+ # @param [Object] object
8
+ # @return [Void]
9
+ def self.included(object)
10
+ object.extend ClassMethods
8
11
  end
9
12
 
10
- def attribute(name: nil, type: nil, kind_of: nil)
11
- type ||= 'accessor'
12
- raise ArgumentError, 'name is a required parameter' unless name
13
- raise ArgumentError, "type must be of type: 'accessor', 'reader', or 'writer'" unless ['accessor', 'reader', 'writer'].include? type
14
-
15
- if ['accessor', 'reader'].include?(type)
16
- define_method name.to_s do
17
- instance_variable_get "@#{name}"
18
- end
19
- end
20
-
21
- if ['accessor', 'writer'].include?(type)
22
- if kind_of.nil?
23
- define_method "#{name}=" do |value|
24
- instance_variable_set "@#{name}", value
25
- end
26
- else
27
- define_method "#{name}=" do |value|
28
- raise ArgumentError, "parameter #{name} (#{value.class}) is not a kind of (#{kind_of})" unless value.is_a?(kind_of) || value.nil?
29
- instance_variable_set "@#{name}", value
30
- end
31
- end
32
- end
33
-
34
- attributes.push name.to_sym
35
- end
36
-
37
- def create(args = {})
38
- object = new
39
- attributes.each { |l| object.send "#{l}=".to_sym, args[l] }
40
- object
13
+ # Returns the hash of built attributes
14
+ # @return [Hash] the name, type, and kind_of built attributes.
15
+ def attributes
16
+ self.class.attributes
41
17
  end
42
18
  end
@@ -0,0 +1,54 @@
1
+ module Creatable
2
+ # Class methods that get mixed in.
3
+ module ClassMethods
4
+ # Returns the list of attributes attatched to this object
5
+ # @return [Hash] the current attributes
6
+ def attributes
7
+ @attributes ||= {}
8
+ @attributes
9
+ end
10
+
11
+ # Replacement for attr_* Will build the same getter/setter methods.
12
+ # will also include a kind_of check.
13
+ # @param [String] name name of the attribute
14
+ # @param [String] type accessor, reader, or writer
15
+ # @param [Class] kind_of class that this can be set too
16
+ # @raise [ArgumentError] if name is not supplied
17
+ # @raise [ArgumentError] if the type is not accessor, reader, or writer
18
+ # @return [Void]
19
+ def attribute(name: nil, type: 'accesor', kind_of: nil)
20
+ raise ArgumentError, 'name is a required parameter' unless name
21
+ raise ArgumentError, "type must be of type: 'accessor', 'reader', or 'writer'" unless ['accessor', 'reader', 'writer'].include? type
22
+
23
+ if ['accessor', 'reader'].include?(type)
24
+ define_method name.to_s do
25
+ instance_variable_get "@#{name}"
26
+ end
27
+ end
28
+
29
+ if ['accessor', 'writer'].include?(type)
30
+ if kind_of.nil?
31
+ define_method("#{name}=") { |value| instance_variable_set "@#{name}", value }
32
+ else
33
+ define_method("#{name}=") do |value|
34
+ raise ArgumentError, "parameter #{name} (#{value.class}) is not a kind of (#{kind_of})" unless value.is_a?(kind_of) || value.nil?
35
+ instance_variable_set "@#{name}", value
36
+ end
37
+ end
38
+ end
39
+
40
+ attributes.merge!(name: name, type: type, kind_of: kind_of)
41
+ nil
42
+ end
43
+
44
+ # Create a new instance of a given object. Allows you to pass in any attribute.
45
+ # @param [Hash] arg key/value pairs for existing attributes
46
+ # @return [Object] Newly created object
47
+ def create(arg = {})
48
+ object = new
49
+ key, value = arg.flatten
50
+ attributes.each { |_l| object.instance_variable_set "@#{key}", value }
51
+ object
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Creatable
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '2.0.0'.freeze # VERSION
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: creatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -228,18 +228,23 @@ executables: []
228
228
  extensions: []
229
229
  extra_rdoc_files: []
230
230
  files:
231
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
231
232
  - ".gitignore"
233
+ - ".gitlab-ci.yml"
232
234
  - ".rspec"
233
235
  - ".rubocop.yml"
234
- - ".travis.yml"
236
+ - CODE_OF_CONDUCT.md
235
237
  - Gemfile
236
238
  - Guardfile
239
+ - LICENSE
237
240
  - README.md
238
241
  - Rakefile
242
+ - _config.yml
239
243
  - bin/console
240
244
  - bin/setup
241
245
  - creatable.gemspec
242
246
  - lib/creatable.rb
247
+ - lib/creatable/class_methods.rb
243
248
  - lib/creatable/version.rb
244
249
  homepage: https://github.com/erniebrodeur/creatable
245
250
  licenses: []
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.16.1