clazz_extensions 0.0.1 → 0.0.2

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: 921f39aa194173e6c36dc2770f9c267a44bf9d62
4
- data.tar.gz: 81bbd08529bbde55afaf127c25d246c11dfebe50
3
+ metadata.gz: 919398eecd3d7500b12f90be266ef589afad01fd
4
+ data.tar.gz: 7910d8f796a8ec1ea13e6aa50045ff47a9ec3d7c
5
5
  SHA512:
6
- metadata.gz: cafda64f9ebab6df1cf4db9ab8e37a67a5435e59b37a4cac604c3e6ae9e5e5b89f24c3911552c77109d00c0fa498d1c451c47f9ed399a63036d0cf3b8e35dfc0
7
- data.tar.gz: d792aab7ba33efc03724313a60b837fc3a559d953848bb1a796bdcfb8c73911b9a30b165b44afcc3df9c01a72a6ed3ca8b79f00970b71972f3d5ffcf0c3af596
6
+ metadata.gz: 76df37f001483a83c597425ac0f20c166d1c7225d13b2fc0ea9e2f71eab3b2f2cd75e9900fb98209da43456d018157bcb152459f73e7e65a3956e07b840200be
7
+ data.tar.gz: 7ee365e5f358d0668f505d190ce4b01a3c701699000a43495a01c853d5853b8b4f037ea17aeb7dbaee73ee9efd2607b7466131edcee770f81af75b3703e08aed
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore CHANGED
@@ -1,14 +1,49 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -1,4 +1,14 @@
1
- source 'https://rubygems.org'
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
2
5
 
3
- # Specify your gem's dependencies in clazz_extensions.gemspec
4
- gemspec
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.2.5)
9
+ docile (1.1.5)
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.8)
13
+ github_api (0.12.1)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.4)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 3.2)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.3)
20
+ oauth2
21
+ hashie (3.3.1)
22
+ highline (1.6.21)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (1.0.0)
34
+ mini_portile (0.6.0)
35
+ multi_json (1.10.1)
36
+ multi_xml (0.5.5)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.3.1)
39
+ mini_portile (= 0.6.0)
40
+ oauth2 (1.0.0)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.5.2)
47
+ rake (10.3.2)
48
+ rdoc (3.12.2)
49
+ json (~> 1.4)
50
+ rspec (3.1.0)
51
+ rspec-core (~> 3.1.0)
52
+ rspec-expectations (~> 3.1.0)
53
+ rspec-mocks (~> 3.1.0)
54
+ rspec-core (3.1.7)
55
+ rspec-support (~> 3.1.0)
56
+ rspec-expectations (3.1.2)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.1.0)
59
+ rspec-mocks (3.1.3)
60
+ rspec-support (~> 3.1.0)
61
+ rspec-support (3.1.2)
62
+ simplecov (0.9.1)
63
+ docile (~> 1.1.0)
64
+ multi_json (~> 1.0)
65
+ simplecov-html (~> 0.8.0)
66
+ simplecov-html (0.8.0)
67
+ thread_safe (0.3.4)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (~> 1.0)
74
+ jeweler (~> 2.0.1)
75
+ rdoc (~> 3.12)
76
+ rspec
77
+ simplecov
data/LICENSE.txt CHANGED
@@ -1,6 +1,4 @@
1
- Copyright (c) 2014 hiraokashogi
2
-
3
- MIT License
1
+ Copyright (c) 2014 hiraoka
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining
6
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,31 +1,37 @@
1
- # ClazzExtensions
1
+ #What is clazz_extensions
2
2
 
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
3
+ Add utility methods on defined class.
8
4
 
5
+ ##example
9
6
  ```ruby
10
- gem 'clazz_extensions'
7
+ "example_class".classify #=> "ExampleClass"
8
+ "example/class_a".classify #=> "Example::ClassA"
9
+ [:a, :b, :c, :a, :d, :c].duplication #=> [:a, :c]
11
10
  ```
12
11
 
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install clazz_extensions
12
+ ## How to Use
13
+ add all
14
+ ```ruby
15
+ ClazzExtension.load do
16
+ array :all
17
+ string :all
18
+ end
19
+ ```
20
20
 
21
- ## Usage
21
+ add specific methods
22
+ ```ruby
23
+ ClazzExtension.load do
24
+ string add: [:classify ]
25
+ array add: [:duplication, :unduplication ]
26
+ end
27
+ ```
22
28
 
23
- TODO: Write usage instructions here
29
+ add every methods that excluding specific
30
+ ```ruby
31
+ ClazzExtension.load do
32
+ string refect: [:to_const ]
33
+ array refect: [:duplication! ]
34
+ end
35
+ ```
24
36
 
25
- ## Contributing
26
37
 
27
- 1. Fork it ( https://github.com/[my-github-username]/clazz_extensions/fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,50 @@
1
- require "bundler/gem_tasks"
1
+ # encoding: utf-8
2
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
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "clazz_extensions"
18
+ gem.homepage = "http://github.com/hiraoka/clazz_extensions"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{TODO: one-line summary of your gem}
21
+ gem.description = %Q{TODO: longer description of your gem}
22
+ gem.email = "hiraokashogi@gmail.com"
23
+ gem.authors = ["hiraoka"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "clazz_extensions #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.files = `git ls-files`.split("\n")
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
25
  end
@@ -0,0 +1,23 @@
1
+ module ClazzExtensions
2
+ class Array < Base
3
+ @methoz = [:duplicate, :duplicate!, :unduplicate]
4
+ def duplication( clazz, _ )
5
+ clazz.select { |v|
6
+ clazz.count( v ) > 1
7
+ }.uniq!
8
+ end
9
+
10
+ def duplication!( clazz, _ )
11
+ duplicate( clazz, args ).each { |v|
12
+ clazz.delete( v )
13
+ }
14
+ end
15
+
16
+ def unduplication( clazz, _ )
17
+ unduplicate_value = clazz.select { |v|
18
+ clazz.count( v ) <= 1
19
+ }
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,75 @@
1
+ module ClazzExtensions
2
+ class Base
3
+ class << self
4
+ def add( methoz )
5
+ @include_methoz ||= []
6
+ @include_methoz << methoz
7
+ @include_methoz.flatten!.uniq!
8
+ end
9
+
10
+ def all( _ )
11
+ @include_methoz = instance_variable_get( :@methoz ).dup
12
+ end
13
+
14
+ def reject( methoz )
15
+ @include_methoz ||= instance_variable_get( :@methoz ).dup
16
+ delete( methoz )
17
+ end
18
+
19
+ def reject_all( _ )
20
+ delete( @include_methoz )
21
+ @include_methoz = nil
22
+ end
23
+
24
+ def delete( methoz )
25
+ m = exist_const_get( include_module )
26
+ [methoz].flatten.compact.each { |method|
27
+ if @include_methoz.delete method
28
+ if m and m.method_defined?( method )
29
+ m.instance_eval("remove_method( :#{method} )" ) if m
30
+ end
31
+ end
32
+ }
33
+ end
34
+
35
+ def include!
36
+ if const_defined? include_module
37
+ clazz = exist_const_get("::" + target_class)
38
+ clazz.instance_eval( "include( #{include_module} )" )
39
+ end
40
+ end
41
+
42
+ def method_define
43
+ [@include_methoz].flatten.compact.each do |m|
44
+ if method_defined?( m )
45
+ eval <<-QUIT
46
+ module #{include_module}
47
+ def #{m}( *args )
48
+ #{self}.new.__send__(:"#{m}", self, args)
49
+ end
50
+ end
51
+ QUIT
52
+ end
53
+ end
54
+ end
55
+
56
+ def target_class
57
+ self.to_s.split( "::" ).last
58
+ end
59
+
60
+ def exist_const_get( clazz_name )
61
+ if const_defined?( clazz_name )
62
+ const_get( clazz_name )
63
+ end
64
+ end
65
+
66
+ def include_module
67
+ eval <<-QUIT
68
+ module ::Extension
69
+ end
70
+ QUIT
71
+ "::Extension::" + self.to_s.split( "::" ).last
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,27 @@
1
+ module ClazzExtensions
2
+ class String < Base
3
+ @methoz = [:classify, :to_const, :classify2]
4
+ def classify( clazz, _ )
5
+ to_class_name( clazz )
6
+ end
7
+
8
+ def to_const( clazz, _ )
9
+ clazz_name = to_class_name( clazz )
10
+
11
+ if Class.const_defined?( clazz_name )
12
+ Class.const_get( clazz_name )
13
+ else
14
+ nil
15
+ end
16
+ end
17
+
18
+ def classify2( clazz, args )
19
+ to_class_name( clazz + "_" + args.join("_") )
20
+ end
21
+
22
+ private
23
+ def to_class_name( clazz )
24
+ clazz.gsub("/","::_").split("_").map { |str| str.capitalize }.join( "" )
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module ClazzExtensions
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,67 @@
1
+ require "clazz_extensions"
2
+
3
+ describe "ClazzExtensions" do
4
+ describe "load method" do
5
+ before do
6
+ ClazzExtension.load do
7
+ string :reject_all
8
+ end
9
+ end
10
+
11
+ it "not include all methods at String class" do
12
+ ClazzExtension.load do
13
+ string :all
14
+ end
15
+ ClazzExtension.load do
16
+ string :reject_all
17
+ end
18
+
19
+ included_module = String.included_modules.index(Extension::String)
20
+ expect( included_module ).not_to be( nil )
21
+ expect( String.method_defined?( :classify ) ).to be( false )
22
+ expect( String.method_defined?( :classify2 ) ).to be( false )
23
+ expect( String.method_defined?( :to_const ) ).to be( false )
24
+ end
25
+
26
+ it "include Extensions::String at String class" do
27
+ ClazzExtension.load do
28
+ string :all
29
+ end
30
+
31
+ included_module = String.included_modules.index(Extension::String)
32
+ expect( included_module ).not_to be( nil )
33
+ end
34
+
35
+ it "included only specific mehtod at String class" do
36
+ ClazzExtension.load do
37
+ string add: [:classify]
38
+ end
39
+
40
+ included_module = String.included_modules.index(Extension::String)
41
+ expect( included_module ).not_to be( nil )
42
+ expect( String.method_defined?( :classify ) ).to be( true )
43
+ end
44
+
45
+ it "not included specific mehtod at String class" do
46
+ ClazzExtension.load do
47
+ string reject: [:classify]
48
+ end
49
+
50
+ included_module = String.included_modules.index(Extension::String)
51
+ expect( included_module ).not_to be( nil )
52
+ expect( String.method_defined?( :classify ) ).to be( false )
53
+ end
54
+
55
+ it "included all mehtod at String class" do
56
+ ClazzExtension.load do
57
+ string :all
58
+ end
59
+
60
+ included_module = String.included_modules.index(Extension::String)
61
+ expect( included_module ).not_to be( nil )
62
+ expect( String.method_defined?( :classify ) ).to be( true )
63
+ expect( String.method_defined?( :to_const ) ).to be( true )
64
+ expect( String.method_defined?( :classify2 ) ).to be( true )
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'clazz_extensions'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clazz_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hiraokashogi
@@ -45,14 +45,22 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".document"
48
49
  - ".gitignore"
50
+ - ".rspec"
49
51
  - Gemfile
52
+ - Gemfile.lock
50
53
  - LICENSE.txt
51
54
  - README.md
52
55
  - Rakefile
53
56
  - clazz_extensions.gemspec
54
57
  - lib/clazz_extensions.rb
58
+ - lib/clazz_extensions/array.rb
59
+ - lib/clazz_extensions/base.rb
60
+ - lib/clazz_extensions/string.rb
55
61
  - lib/clazz_extensions/version.rb
62
+ - spec/clazz_extensions_spec.rb
63
+ - spec/spec_helper.rb
56
64
  homepage: ''
57
65
  licenses:
58
66
  - MIT
@@ -77,5 +85,7 @@ rubygems_version: 2.2.2
77
85
  signing_key:
78
86
  specification_version: 4
79
87
  summary: Add utility methods on defined class.
80
- test_files: []
88
+ test_files:
89
+ - spec/clazz_extensions_spec.rb
90
+ - spec/spec_helper.rb
81
91
  has_rdoc: