fugazi 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/LICENSE +20 -0
  4. data/README.md +32 -0
  5. data/Rakefile +20 -0
  6. data/fugazi.gemspec +35 -0
  7. data/lib/fugazi.rb +74 -0
  8. metadata +65 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf08af66cc7b010daf380b3a00ce5c5e9a43aada
4
+ data.tar.gz: 0a1f6b0316f0ad6fc54fdd7c3f9c4bd8dce77a4b
5
+ SHA512:
6
+ metadata.gz: 03e29c5b1692969121ccaca1146003cfc4f4b82d98bd2d0257fd17a50eb30ead16a8d8dbd2727ca7a7845f49ba57ebd13e902bd0265cfc1acc65d08ba401acc9
7
+ data.tar.gz: 41ce9f9f5cda233d9bef9d95fdcbead7f98f280c9e066c190ae8dcec3e7c5b8d61e6154afb1a261dd59633c8d2018bc34ed0e879be4ad98f2e794d3fea853366
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem 'rspec'
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alexander Ivanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ #fugazi
2
+
3
+ A simple gem providing a dsl for defining and initializing class fields
4
+
5
+ ## example
6
+
7
+ ```ruby
8
+ class Box
9
+ include Fugazi
10
+
11
+ fields :content
12
+ defaults x: 0, y: 0
13
+ keywords z: 0
14
+ end
15
+
16
+ # <=>
17
+ class Box
18
+ attr_reader :content, :x, :y, :z
19
+
20
+ def initialize(content, x = 0, y = 0, z: 0)
21
+ @content = content
22
+ @x = x
23
+ @y = y
24
+ @z = z
25
+ end
26
+ end
27
+ ```
28
+
29
+ ##todo
30
+
31
+ block support
32
+
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new(:spec) do |spec|
17
+ spec.pattern = FileList['spec/**/*_spec.rb']
18
+ end
19
+ task :default => :spec
20
+
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "fugazi"
3
+ s.version = "0.0.2"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.require_paths = ["lib"]
7
+ s.authors = ["Alexander Ivanov"]
8
+ s.date = "2015-10-11"
9
+ s.description = "A simple gem providing a dsl for defining and initializing class fields"
10
+ s.email = "alehander42@gmail.com"
11
+ s.executables = []
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.md"
15
+ ]
16
+ s.files = [
17
+ "Gemfile",
18
+ "LICENSE",
19
+ "README.md",
20
+ "Rakefile",
21
+ "lib/fugazi.rb",
22
+ "fugazi.gemspec"
23
+ ]
24
+ s.homepage = "http://github.com/alehander42/fugazi"
25
+ s.licenses = ["MIT"]
26
+ s.rubygems_version = "2.4.8"
27
+ s.summary = "A simple gem providing a dsl for defining and initializing class fields"
28
+
29
+ if s.respond_to? :specification_version then
30
+ s.specification_version = 4
31
+ s.add_development_dependency(%q<rspec>, ["= 3.3.0"])
32
+ end
33
+ end
34
+
35
+
@@ -0,0 +1,74 @@
1
+ module Fugazi
2
+ def self.included(receiver)
3
+ receiver.send :include, InstanceMethods
4
+ receiver.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def defaults(**kwargs)
9
+ @defaults = kwargs
10
+ end
11
+
12
+ def fields(*args)
13
+ @fields = args
14
+ end
15
+
16
+ def keywords(*args, **kwargs)
17
+ @keywords = args
18
+ @default_keywords = kwargs
19
+ end
20
+
21
+ def default_args
22
+ @defaults || {}
23
+ end
24
+
25
+ def field_args
26
+ @fields || []
27
+ end
28
+
29
+ def keyword_args
30
+ @keywords || []
31
+ end
32
+
33
+ def default_keyword_args
34
+ @default_keywords || {}
35
+ end
36
+ end
37
+
38
+ module InstanceMethods
39
+ def initialize(*args, **kwargs)
40
+ e = args.length - self.class.field_args.length - 1
41
+ labels = self.class.field_args + (self.class.default_args.to_a[0..e] || []).map { |n, _| n }
42
+ labels.zip(args).each do |label, arg|
43
+ instance_variable_set "@#{label}", arg
44
+ self.class.send :attr_reader, label
45
+ end
46
+
47
+ (self.class.default_args.to_a[e + 1..-1] || []).each do |default, value|
48
+ instance_variable_set "@#{default}", value
49
+ self.class.send :attr_reader, default
50
+ end
51
+
52
+ kwargs.each do |key, arg|
53
+ instance_variable_set "@#{key}", arg
54
+ self.class.send :attr_reader, key
55
+ end
56
+
57
+ self.class.default_keyword_args.each do |key, default|
58
+ unless kwargs.key? key
59
+ instance_variable_set "@#{key}", default
60
+ self.class.send :attr_reader, key
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ # class A
68
+ # include Fugazi
69
+ # fields :z
70
+ # defaults y: 2
71
+ # end
72
+
73
+ # a = A.new 2
74
+ # puts a.z, a.y
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fugazi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Ivanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.3.0
27
+ description: A simple gem providing a dsl for defining and initializing class fields
28
+ email: alehander42@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.md
34
+ files:
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - fugazi.gemspec
40
+ - lib/fugazi.rb
41
+ homepage: http://github.com/alehander42/fugazi
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.8
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A simple gem providing a dsl for defining and initializing class fields
65
+ test_files: []