[DRE-commits] [ruby-browser] 01/01: Imported Upstream version 1.0.0

Balasankar C balasankarc-guest at moszumanska.debian.org
Tue Dec 1 11:50:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

balasankarc-guest pushed a commit to annotated tag upstream/1.0.0
in repository ruby-browser.

commit fb0aa6e57e9bee08b8d9de44e45689b4c3871d68
Author: Balasankar C <balasankarc at autistici.org>
Date:   Sun May 17 23:43:11 2015 +0530

    Imported Upstream version 1.0.0
---
 .gitignore                 |  22 +++++++++
 .rspec                     |   2 +
 .travis.yml                |   3 ++
 Gemfile                    |   2 +
 LICENSE                    |  20 ++++++++
 README.rdoc                |  81 ++++++++++++++++++++++++++++++++
 Rakefile                   |  19 ++++++++
 VERSION                    |   1 +
 attr_required.gemspec      |  20 ++++++++
 lib/attr_optional.rb       |  51 ++++++++++++++++++++
 lib/attr_required.rb       |  74 +++++++++++++++++++++++++++++
 metadata.yml               | 105 +++++++++++++++++++++++++++++++++++++++++
 spec/attr_optional_spec.rb |  75 ++++++++++++++++++++++++++++++
 spec/attr_required_spec.rb | 113 +++++++++++++++++++++++++++++++++++++++++++++
 spec/spec_helper.rb        |  37 +++++++++++++++
 15 files changed, 625 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0c7457a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,22 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage*
+rdoc
+pkg
+Gemfile.lock
+
+## PROJECT::SPECIFIC
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..d3ad5a9
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,2 @@
+--color
+--format=documentation
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..46029af
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,3 @@
+rvm:
+  - 1.9.3
+  - 2.0.0
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..817f62a
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,2 @@
+source 'http://rubygems.org'
+gemspec
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..4595a60
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 nov matake
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.rdoc b/README.rdoc
new file mode 100644
index 0000000..8822faf
--- /dev/null
+++ b/README.rdoc
@@ -0,0 +1,81 @@
+= attr_required
+
+This gem provide <code>attr_required</code> and <code>attr_optional</code> like <code>attr_accessor</code>.
+
+{<img src="https://secure.travis-ci.org/nov/attr_required.png" />}[http://travis-ci.org/nov/attr_required]
+
+REQUIRED and OPTIONAL are common terminology in RFCs, and used for protocol parameters.
+This gem helps RFC library developers to define which parameters (attributes in Ruby world) are REQUIRED and which are OPTIONAL.
+It might be also helpful for other developers.
+
+I've developed this gem to use for rack-oauth2, a Rack-based OAuth 2.0 library.
+http://github.com/nov/rack-oauth2
+
+== Installation
+
+  gem install attr_required
+
+== Usage
+
+# Attributes Definitions
+
+  require 'attr_required'
+  require 'attr_optional'
+
+  class A
+    include AttrRequired, AttrOptional
+    attr_required :required_a
+    attr_optional :optional_a
+  end
+
+  class B < A
+    attr_required :required_b
+    attr_optional :optional_b
+  end
+
+# Class Methods
+
+  A.required_attributes #=> [:required_a]
+  B.required_attributes #=> [:required_a, :required_b]
+  A.optional_attributes #=> [:optional_a]
+  B.optional_attributes #=> [:optional_a, :optional_b]
+
+  A.attr_required?(:required_a) #=> true
+  B.attr_optional?(:optional_b) #=> true
+
+# Instance Methods
+
+  @a = A.new
+  @b = B.new
+
+  @a.required_attributes #=> [:required_a]
+  @b.required_attributes #=> [:required_a, :required_b]
+  @a.optional_attributes #=> [:optional_a]
+  @b.optional_attributes #=> [:optional_a, :optional_b]
+
+  @a.attr_required?(:required_a) #=> true
+  @a.attr_optional?(:optiona_a)  #=> true
+
+  @a.attr_missing? #=> true
+  @a.attr_missing  #=> [:required_a]
+  @a.attr_missing! #=> raise AttrRequired::AttrMissing
+  @a.required_a = "foo"
+  @a.attr_missing? #=> false
+  @a.attr_missing  #=> []
+  @a.attr_missing! #=> do nothing
+
+Check spec/attr_(required|optional).rb for more details.
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+  future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2010 nov matake. See LICENSE for details.
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..24e3688
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,19 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+
+namespace :coverage do
+  desc "Open coverage report"
+  task :report do
+    require 'simplecov'
+    `open "#{File.join SimpleCov.coverage_path, 'index.html' }"`
+  end
+end
+
+task :spec do
+  Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
+end
+
+task :default => :spec
\ No newline at end of file
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..afaf360
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+1.0.0
\ No newline at end of file
diff --git a/attr_required.gemspec b/attr_required.gemspec
new file mode 100644
index 0000000..b07481f
--- /dev/null
+++ b/attr_required.gemspec
@@ -0,0 +1,20 @@
+Gem::Specification.new do |s|
+  s.name = "attr_required"
+  s.version = File.read("VERSION")
+  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
+  s.authors = ["nov matake"]
+  s.description = %q{attr_required and attr_optional}
+  s.summary = %q{attr_required and attr_optional}
+  s.email = "nov at matake.jp"
+  s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
+  s.license = 'MIT'
+  s.rdoc_options = ["--charset=UTF-8"]
+  s.homepage = "http://github.com/nov/attr_required"
+  s.require_paths = ["lib"]
+  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+  s.files = `git ls-files`.split("\n")
+  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+  s.add_development_dependency "rake", ">= 0.8"
+  s.add_development_dependency "simplecov"
+  s.add_development_dependency "rspec", ">= 2"
+end
diff --git a/lib/attr_optional.rb b/lib/attr_optional.rb
new file mode 100644
index 0000000..f93bdb3
--- /dev/null
+++ b/lib/attr_optional.rb
@@ -0,0 +1,51 @@
+module AttrOptional
+
+  def self.included(klass)
+    klass.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+
+    def inherited(klass)
+      super
+      unless optional_attributes.empty?
+        klass.attr_optional *optional_attributes
+      end
+    end
+
+    def attr_optional(*keys)
+      if defined? undef_required_attributes
+        undef_required_attributes *keys
+      end
+      optional_attributes.concat(keys)
+      attr_accessor *keys
+    end
+
+    def attr_optional?(key)
+      optional_attributes.include?(key)
+    end
+
+    def optional_attributes
+      @optional_attributes ||= []
+    end
+
+    def undef_optional_attributes(*keys)
+      keys.each do |key|
+        if attr_optional?(key)
+          undef_method key, :"#{key}="
+          optional_attributes.delete key
+        end
+      end
+    end
+
+  end
+
+  def optional_attributes
+    self.class.optional_attributes
+  end
+
+  def attr_optional?(key)
+    self.class.attr_optional? key
+  end
+
+end
\ No newline at end of file
diff --git a/lib/attr_required.rb b/lib/attr_required.rb
new file mode 100644
index 0000000..1e3a15e
--- /dev/null
+++ b/lib/attr_required.rb
@@ -0,0 +1,74 @@
+module AttrRequired
+
+  class AttrMissing < StandardError; end
+
+  def self.included(klass)
+    klass.send :extend, ClassMethods
+  end
+
+  module ClassMethods
+
+    def inherited(klass)
+      super
+      unless required_attributes.empty?
+        klass.attr_required *required_attributes
+      end
+    end
+
+    def attr_required(*keys)
+      if defined? undef_optional_attributes
+        undef_optional_attributes *keys
+      end
+      required_attributes.concat keys
+      attr_accessor *keys
+    end
+
+    def attr_required?(key)
+      required_attributes.include? key
+    end
+
+    def required_attributes
+      @required_attributes ||= []
+    end
+
+    def undef_required_attributes(*keys)
+      keys.each do |key|
+        if attr_required?(key)
+          undef_method key, :"#{key}="
+          required_attributes.delete key
+        end
+      end
+    end
+
+  end
+
+  def required_attributes
+    self.class.required_attributes
+  end
+
+  def attr_required?(key)
+    self.class.attr_required? key
+  end
+
+  def attr_missing?
+    !attr_missing.empty?
+  end
+
+  def attr_missing!
+    if attr_missing?
+      raise AttrMissing.new("'#{attr_missing.join('\', \'')}' required.")
+    end
+  end
+
+  def attr_missing
+    required_attributes.select do |key|
+      value = send(key)
+      if value.respond_to?(:empty?)
+        value.empty?
+      else
+        value.nil?
+      end
+    end
+  end
+
+end
\ No newline at end of file
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..e996c39
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,105 @@
+--- !ruby/object:Gem::Specification
+name: attr_required
+version: !ruby/object:Gem::Version
+  version: 1.0.0
+platform: ruby
+authors:
+- nov matake
+autorequire: 
+bindir: bin
+cert_chain: []
+date: 2014-01-29 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+  name: rake
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '0.8'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '0.8'
+- !ruby/object:Gem::Dependency
+  name: simplecov
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '0'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '0'
+- !ruby/object:Gem::Dependency
+  name: rspec
+  requirement: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '2'
+  type: :development
+  prerelease: false
+  version_requirements: !ruby/object:Gem::Requirement
+    requirements:
+    - - '>='
+      - !ruby/object:Gem::Version
+        version: '2'
+description: attr_required and attr_optional
+email: nov at matake.jp
+executables: []
+extensions: []
+extra_rdoc_files:
+- LICENSE
+- README.rdoc
+files:
+- .gitignore
+- .rspec
+- .travis.yml
+- Gemfile
+- LICENSE
+- README.rdoc
+- Rakefile
+- VERSION
+- attr_required.gemspec
+- lib/attr_optional.rb
+- lib/attr_required.rb
+- spec/attr_optional_spec.rb
+- spec/attr_required_spec.rb
+- spec/spec_helper.rb
+homepage: http://github.com/nov/attr_required
+licenses:
+- MIT
+metadata: {}
+post_install_message: 
+rdoc_options:
+- --charset=UTF-8
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - '>='
+    - !ruby/object:Gem::Version
+      version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+  requirements:
+  - - '>='
+    - !ruby/object:Gem::Version
+      version: 1.3.6
+requirements: []
+rubyforge_project: 
+rubygems_version: 2.0.3
+signing_key: 
+specification_version: 4
+summary: attr_required and attr_optional
+test_files:
+- spec/attr_optional_spec.rb
+- spec/attr_required_spec.rb
+- spec/spec_helper.rb
diff --git a/spec/attr_optional_spec.rb b/spec/attr_optional_spec.rb
new file mode 100644
index 0000000..22e599d
--- /dev/null
+++ b/spec/attr_optional_spec.rb
@@ -0,0 +1,75 @@
+require 'spec_helper.rb'
+
+describe AttrOptional do
+  before do
+    @a, @b, @c = A.new, B.new, C.new
+  end
+
+  describe '.attr_optional' do
+    it 'should define accessible attributes' do
+      @a.should respond_to :attr_optional_a
+      @a.should respond_to :attr_optional_a=
+      @b.should respond_to :attr_optional_b
+      @b.should respond_to :attr_optional_b=
+    end
+
+    it 'should be inherited' do
+      @b.should respond_to :attr_optional_a
+      @b.should respond_to :attr_optional_a=
+    end
+
+    context 'when already required' do
+      it 'should be optional' do
+        @c.attr_required?(:attr_required_b).should be_false
+        @c.attr_optional?(:attr_required_b).should be_true
+      end
+    end
+
+    context 'when AttrRequired not included' do
+      it 'should do nothing' do
+        OnlyOptional.optional_attributes.should == [:only_optional]
+      end
+    end
+  end
+
+  describe '.attr_optional?' do
+    it 'should answer whether the attributes is optional or not' do
+      A.attr_optional?(:attr_optional_a).should be_true
+      B.attr_optional?(:attr_optional_a).should be_true
+      B.attr_optional?(:attr_optional_b).should be_true
+      B.attr_optional?(:to_s).should be_false
+    end
+  end
+
+  describe '#attr_optional?' do
+    it 'should answer whether the attributes is optional or not' do
+      @a.attr_optional?(:attr_optional_a).should be_true
+      @b.attr_optional?(:attr_optional_a).should be_true
+      @b.attr_optional?(:attr_optional_b).should be_true
+      @b.attr_optional?(:to_s).should be_false
+    end
+  end
+
+  describe '.optional_attributes' do
+    it 'should return all optional attributes keys' do
+      A.optional_attributes.should == [:attr_optional_a]
+      B.optional_attributes.should == [:attr_optional_a, :attr_optional_b]
+    end
+  end
+
+  describe '#optional_attributes' do
+    it 'should return optional attributes keys' do
+      @a.optional_attributes.should == [:attr_optional_a]
+      @b.optional_attributes.should == [:attr_optional_a, :attr_optional_b]
+    end
+  end
+
+  describe '.undef_optional_attributes' do
+    it 'should undefine accessors and remove from optional attributes' do
+      C.optional_attributes.should_not include :attr_optional_a
+      @c.optional_attributes.should_not include :attr_optional_a
+      @c.should_not respond_to :attr_optional_a
+      @c.should_not respond_to :attr_optional_a=
+    end
+  end
+end
diff --git a/spec/attr_required_spec.rb b/spec/attr_required_spec.rb
new file mode 100644
index 0000000..47c0388
--- /dev/null
+++ b/spec/attr_required_spec.rb
@@ -0,0 +1,113 @@
+require 'spec_helper.rb'
+
+describe AttrRequired do
+  before do
+    @a, @b, @c = A.new, B.new, C.new
+  end
+
+  describe '.attr_required' do
+    it 'should define accessible attributes' do
+      @a.should respond_to :attr_required_a
+      @a.should respond_to :attr_required_a=
+      @b.should respond_to :attr_required_b
+      @b.should respond_to :attr_required_b=
+    end
+
+    it 'should be inherited' do
+      @b.should respond_to :attr_required_a
+      @b.should respond_to :attr_required_a=
+    end
+
+    context 'when already optional' do
+      it 'should be optional' do
+        @c.attr_required?(:attr_optional_b).should be_true
+        @c.attr_optional?(:attr_optional_b).should be_false
+      end
+    end
+
+    context 'when AttrOptional not included' do
+      it 'should do nothing' do
+        OnlyRequired.required_attributes.should == [:only_required]
+      end
+    end
+  end
+
+  describe '.attr_required?' do
+    it 'should answer whether the attributes is required or not' do
+      A.attr_required?(:attr_required_a).should be_true
+      B.attr_required?(:attr_required_a).should be_true
+      B.attr_required?(:attr_required_b).should be_true
+      B.attr_required?(:to_s).should be_false
+    end
+  end
+
+  describe '#attr_required?' do
+    it 'should answer whether the attributes is required or not' do
+      @a.attr_required?(:attr_required_a).should be_true
+      @b.attr_required?(:attr_required_a).should be_true
+      @b.attr_required?(:attr_required_b).should be_true
+      @a.attr_required?(:attr_required_b).should be_false
+      @b.attr_required?(:to_s).should be_false
+    end
+  end
+
+  describe '#attr_missing?' do
+    it 'should answer whether any attributes are missing' do
+      @a.attr_missing?.should be_true
+      @b.attr_missing?.should be_true
+      @a.attr_required_a = 'attr_required_a'
+      @b.attr_required_a = 'attr_required_a'
+      @a.attr_missing?.should be_false
+      @b.attr_missing?.should be_true
+      @b.attr_required_b = 'attr_required_b'
+      @b.attr_missing?.should be_false
+    end
+  end
+
+  describe '#attr_missing!' do
+    it 'should raise AttrMissing error when any attributes are missing' do
+      lambda { @a.attr_missing! }.should raise_error(AttrRequired::AttrMissing)
+      lambda { @b.attr_missing! }.should raise_error(AttrRequired::AttrMissing)
+      @a.attr_required_a = 'attr_required_a'
+      @b.attr_required_a = 'attr_required_a'
+      lambda { @a.attr_missing! }.should_not raise_error
+      lambda { @b.attr_missing! }.should raise_error(AttrRequired::AttrMissing)
+      @b.attr_required_b = 'attr_required_b'
+      lambda { @b.attr_missing! }.should_not raise_error
+    end
+  end
+
+  describe '#attr_missing' do
+    it 'should return missing attributes keys' do
+      @a.attr_missing.should == [:attr_required_a]
+      @b.attr_missing.should == [:attr_required_a, :attr_required_b]
+      @a.attr_required_a = 'attr_required_a'
+      @b.attr_required_a = 'attr_required_a'
+      @a.attr_missing.should == []
+      @b.attr_missing.should == [:attr_required_b]
+    end
+  end
+
+  describe '.required_attributes' do
+    it 'should return all required attributes keys' do
+      A.required_attributes.should == [:attr_required_a]
+      B.required_attributes.should == [:attr_required_a, :attr_required_b]
+    end
+  end
+
+  describe '#required_attributes' do
+    it 'should return required attributes keys' do
+      @a.required_attributes.should == [:attr_required_a]
+      @b.required_attributes.should == [:attr_required_a, :attr_required_b]
+    end
+  end
+
+  describe '.undef_required_attributes' do
+    it 'should undefine accessors and remove from required attributes' do
+      C.required_attributes.should_not include :attr_required_a
+      @c.required_attributes.should_not include :attr_required_a
+      @c.should_not respond_to :attr_required_a
+      @c.should_not respond_to :attr_required_a=
+    end
+  end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..8026698
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,37 @@
+require 'simplecov'
+
+SimpleCov.start do
+  add_filter 'spec'
+end
+
+require 'attr_required'
+require 'attr_optional'
+require 'rspec'
+
+class A
+  include AttrRequired, AttrOptional
+  attr_required :attr_required_a
+  attr_optional :attr_optional_a
+end
+
+class B < A
+  attr_required :attr_required_b
+  attr_optional :attr_optional_b
+end
+
+class C < B
+  undef_required_attributes :attr_required_a
+  undef_optional_attributes :attr_optional_a
+  attr_optional :attr_required_b
+  attr_required :attr_optional_b
+end
+
+class OnlyRequired
+  include AttrRequired
+  attr_required :only_required
+end
+
+class OnlyOptional
+  include AttrOptional
+  attr_optional :only_optional
+end
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-browser.git



More information about the Pkg-ruby-extras-commits mailing list