From 5a96aabeda1d9efe60f66d68537d5587d061f5e5 Mon Sep 17 00:00:00 2001 From: elliottcable Date: Thu, 9 Oct 2008 20:35:18 -0800 Subject: [PATCH] atterisk --- .gitignore | 3 ++ .manifest | 6 +++ README.markdown | 139 +++++++++++++++++++++++++++++++++++++++++++++++ Rakefile.rb | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ attr_splat.gemspec | 116 +++++++++++++++++++++++++++++++++++++++ lib/attr_splat.rb | 3 ++ spec/attr_splat_spec.rb | 5 ++ spec/spec_helper.rb | 6 +++ 8 files changed, 418 insertions(+) create mode 100644 .gitignore create mode 100644 .manifest create mode 100644 README.markdown create mode 100644 Rakefile.rb create mode 100644 attr_splat.gemspec create mode 100644 lib/attr_splat.rb create mode 100644 spec/attr_splat_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92add0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.yardoc +meta +pkg \ No newline at end of file diff --git a/.manifest b/.manifest new file mode 100644 index 0000000..b667186 --- /dev/null +++ b/.manifest @@ -0,0 +1,6 @@ +lib/attr_splat.rb +Rakefile.rb +README.markdown +spec/attr_splat_spec.rb +spec/spec_helper.rb +.manifest diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..08342b4 --- /dev/null +++ b/README.markdown @@ -0,0 +1,139 @@ +attr_* +====== +*`attr_*`* is a library to extend the basic Ruby class/module attribute +functions with some useful functionality. It supports the original attribute +API, as well as additional features such as defaults values for attributes and +attribute initialization. + +Specifically, three types of attribute initialization are supported: + +- none (as per the functionality of the original attr_accessor et al., the + instance variables won’t be initialized to any value — `instance_variable_defined?(:@ivar)` + will return false) +- first-access initialization (the attribute will be undefined until first + accessed) +- instance initialization (the attribute will be defined with the instance, + thus being defined for all parts of the lifecycle of the instance, for all + intents and purposes) + +Usage +----- +`attr_*` exposes a single method, `Module#attr_splat`, that takes a series of +Symbols from which to create attributes, along with an options hash at the end. + +However, most users will want to replace the existing `attr_*` functionality +with this (the API is fully backwards compatible; as long as none of your code +depends on the particular inner workings of the existing `attr_*` methods, it +should continue to work fine as-is). This isn't difficult, and for the most +part amounts to the following: + + class Module + def attr_accessor *args + attr_splat(*args) + end + + def attr_reader *args + opts = args.last.is_a?(Hash) ? args.pop : Hash.new + args << {:writer => false}.merge(opts) + attr_splat(*args) + end + + def attr_writer *args + opts = args.last.is_a?(Hash) ? args.pop : Hash.new + args << {:writer => false}.merge(opts) + attr_splat(*args) + end + end + +If you're lazy, you can shorten the above to something like this: + + Module::attr_splat! + +Using `attr_*` is pretty simple - just use the `attr_*` methods as you +normally would. If you need to supply a default value for an attribute, you +can add a `:default` parameter as follows: + + class Something + attr_accessor :something, :default => "summat" + end + +You can define more than one attribute with the same default at the same time: + + attr_accessor :something, :something_else, :default => "summat" + +Attributes with a default flag will (by default) to the second initialization +method described above - that is, the default value will be initialized into +the attribute's variable only after the first time the attribute's getter is +called. If you want default values to be initialized along with the instance +of the class, you can pass the `:initialize` flag - it's disabled by default, +because it relies on some metaprogrammy magic that this author prefers to +avoid calling into every class all over Ruby's source. + + attr_accessor :something, :something_else, + :default => "summat", :initialze => true + +If you call the initialize flag without a default, the attribute is +initialized to `nil`. + + attr_accessor :something, :something_else, :initialze => true + +Installation +------------ +You can install `attr_*` as a pre-built gem, or as a gem generated directly +from the source. + +The easiest way to install `attr_*` is to use [RubyGems][] to acquire the +latest 'release' version from [RubyForge][], using the `gem` command line tool: + + sudo gem install attr_splat # You'll be asked for your account password. + +Alternatively, you can acquire it (possibly slightly more up-to-date, +depending on how often I update the gemspec) from GitHub as follows: + + # If you've ever done this before, you don't need to do it now - see http://gems.github.com + gem sources -a http://gems.github.com + sudo gem install elliottcable-attr_splat # You'll be asked for your account password. + +Finally, you can build a gem from the latest source yourself. You need [git][], +as well as [Rake][] and [echoe][]: + + git clone git://github.com/elliottcable/attr_splat.git + cd attr_splat + rake package:install # You'll be asked for your account password. + +[RubyGems]: "RubyGems - Ruby package manager" +[RubyForge]: "attr_* on RubyForge" +[git]: "git - Fast Version Control System" +[Rake]: "RAKE - Ruby Make" +[echoe]: "If you don't want to hoe, echoe" + +Contributing +------------ +You can contribute bug fixes or new features to `attr_*` by forking the project +on GitHub (you'll need to register for an account first), and sending me a +pull request once you've committed your changes. + +Links +----- +- [GitHub](http://github.com/elliottcable/attr_splat "attr_* on GitHub") is the + project's primary repository host, and currently also the project's home + page +- [RubyForge](http://rubyforge.org/projects/attr_splat "attr_* on RubyForge") is + out primary RubyGem host, as well as an alternative repository host +- [integrity](http://integrit.yreality.net/attr_splat "attr_* on yreality's integrity server") + is out continuous integration server - if the top build on that page is + green, you can assume the latest git HEAD is safe to run/install/utilize. +- [Gitorious](http://gitorious.org/projects/attr_splat "attr_* on Gitorious") is + an alternative repository host +- [repo.or.cz](http://repo.or.cz/w/attr_splat.git "attr_* on repo.or.cz") is + an alternative repository host + +License +------- +`attr_*` is copyright 2008 by elliott cable. + +`attr_*` is released under the [GNU General Public License v3.0][gpl], which +allows you to freely utilize, modify, and distribute all `attr_*`'s source code +(subject to the terms of the aforementioned license). + +[gpl]: "The GNU General Public License v3.0" \ No newline at end of file diff --git a/Rakefile.rb b/Rakefile.rb new file mode 100644 index 0000000..aed6aaf --- /dev/null +++ b/Rakefile.rb @@ -0,0 +1,140 @@ +($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq! +begin + require 'attr_splat' +rescue LoadError + module AttrSplat; Version = -1; end +end + +# ======================= +# = Gem packaging tasks = +# ======================= +begin + require 'echoe' + + task :package => :'package:install' + task :manifest => :'package:manifest' + namespace :package do + Echoe.new('attr_splat', AttrSplat::Version) do |g| + g.project = 'attr_splat' + g.author = ['elliottcable'] + g.email = ['attr_splat@elliottcable.com'] + g.summary = "attr_* puts Ruby Core's attr_accessor, attr_reader, and attr_reader on steroids" + g.url = 'http://by.elliottcable.name/attr_splat.xhtml' + g.development_dependencies = ['echoe >=3.0.1', 'rspec', 'rcov', 'yard', 'stringray'] + g.manifest_name = '.manifest' + g.ignore_pattern = /^\.git\/|^meta\/|\.gemspec/ + end + + desc 'tests packaged files to ensure they are all present' + task :verify => :package do + # An error message will be displayed if files are missing + if system %(ruby -e "require 'rubygems'; require 'pkg/attr_splat-#{AttrSplat::Version}/lib/attr_splat'") + puts "\nThe library files are present" + end + end + + task :copy_gemspec => [:package] do + pkg = Dir['pkg/*'].select {|dir| File.directory? dir}.last + mv File.join(pkg, pkg.gsub(/^pkg\//,'').gsub(/\-\d+$/,'.gemspec')), './' + end + + desc 'builds a gemspec as GitHub wants it' + task :gemspec => [:package, :copy_gemspec, :clobber_package] + end + +rescue LoadError + desc 'You need the `echoe` gem to package attr_*' + task :package +end + +# ======================= +# = Spec/Coverage tasks = +# ======================= +begin + require 'spec' + require 'rcov' + require 'spec/rake/spectask' + + task :default => :'coverage:run' + task :coverage => :'coverage:run' + namespace :coverage do + Spec::Rake::SpecTask.new(:run) do |t| + t.spec_opts = ["--format", "specdoc"] + t.spec_opts << "--colour" unless ENV['CI'] + t.spec_files = Dir['spec/**/*_spec.rb'].sort + t.libs = ['lib'] + t.rcov = true + t.rcov_opts = [ '--include-file', '"^lib"', '--exclude-only', '".*"'] + t.rcov_dir = File.join('meta', 'coverage') + end + + begin + require 'spec/rake/verify_rcov' + # For the moment, this is the only way I know of to fix RCov. I may + # release the fix as it's own gem at some point in the near future. + require 'stringray/core_ext/spec/rake/verify_rcov' + RCov::VerifyTask.new(:verify) do |t| + t.threshold = 95.0 + t.index_html = File.join('meta', 'coverage', 'index.html') + t.require_exact_threshold = false + end + rescue LoadError + desc 'You need the `stringray` gem to verify coverage' + task :verify + end + + task :open do + system 'open ' + File.join('meta', 'coverage', 'index.html') if PLATFORM['darwin'] + end + end + +rescue LoadError + desc 'You need the `rcov` and `rspec` gems to run specs/coverage' + task :coverage +end + +# ======================= +# = Documentation tasks = +# ======================= +begin + require 'yard' + require 'yard/rake/yardoc_task' + + task :documentation => :'documentation:generate' + namespace :documentation do + YARD::Rake::YardocTask.new :generate do |t| + t.files = ['lib/**/*.rb'] + t.options = ['--output-dir', File.join('meta', 'documentation'), + '--readme', 'README.markdown'] + end + + YARD::Rake::YardocTask.new :dotyardoc do |t| + t.files = ['lib/**/*.rb'] + t.options = ['--no-output', + '--readme', 'README.markdown'] + end + + task :open do + system 'open ' + File.join('meta', 'documentation', 'index.html') if PLATFORM['darwin'] + end + end + +rescue LoadError + desc 'You need the `yard` gem to generate documentation' + task :documentation +end + +# ========= +# = Other = +# ========= +desc 'Removes all meta producs' +task :clobber do + `rm -rf #{File.expand_path(File.join( File.dirname(__FILE__), 'meta' ))}` +end + +desc 'Check everything over before commiting' +task :aok => [:'documentation:generate', :'documentation:open', + :'package:manifest', :'package:gemspec', + :'coverage:run', :'coverage:open', :'coverage:verify'] + +task :ci => [:'documentation:generate', :'coverage:run', :'coverage:verify'] \ No newline at end of file diff --git a/attr_splat.gemspec b/attr_splat.gemspec new file mode 100644 index 0000000..09f0f72 --- /dev/null +++ b/attr_splat.gemspec @@ -0,0 +1,116 @@ + +# Gem::Specification for Attr_splat-0 +# Originally generated by Echoe + +--- !ruby/object:Gem::Specification +name: attr_splat +version: !ruby/object:Gem::Version + version: "0" +platform: ruby +authors: +- elliottcable +autorequire: +bindir: bin + +date: 2008-10-09 00:00:00 -08:00 +default_executable: +dependencies: +- !ruby/object:Gem::Dependency + name: echoe + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 3.0.1 + version: +- !ruby/object:Gem::Dependency + name: rspec + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +- !ruby/object:Gem::Dependency + name: rcov + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +- !ruby/object:Gem::Dependency + name: yard + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +- !ruby/object:Gem::Dependency + name: stringray + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +description: attr_* puts Ruby Core's attr_accessor, attr_reader, and attr_reader on steroids +email: +- attr_splat@elliottcable.com +executables: [] + +extensions: [] + +extra_rdoc_files: +- lib/attr_splat.rb +- README.markdown +files: +- lib/attr_splat.rb +- Rakefile.rb +- README.markdown +- spec/attr_splat_spec.rb +- spec/spec_helper.rb +- .manifest +- attr_splat.gemspec +has_rdoc: true +homepage: http://by.elliottcable.name/attr_splat.xhtml +post_install_message: +rdoc_options: +- --line-numbers +- --inline-source +- --title +- Attr_splat +- --main +- README.markdown +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "1.2" + version: +requirements: [] + +rubyforge_project: attr_splat +rubygems_version: 1.3.0 +specification_version: 2 +summary: attr_* puts Ruby Core's attr_accessor, attr_reader, and attr_reader on steroids +test_files: [] diff --git a/lib/attr_splat.rb b/lib/attr_splat.rb new file mode 100644 index 0000000..54ae449 --- /dev/null +++ b/lib/attr_splat.rb @@ -0,0 +1,3 @@ +module AttrSplat + Version = 0 +end \ No newline at end of file diff --git a/spec/attr_splat_spec.rb b/spec/attr_splat_spec.rb new file mode 100644 index 0000000..e66b7ea --- /dev/null +++ b/spec/attr_splat_spec.rb @@ -0,0 +1,5 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe AttrSplat do + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2443a18 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq! +require 'attr_splat' + +# Require spec here, for things like autotest and rdebug that aren't running +# using the Rakefile. +require 'spec' \ No newline at end of file -- 2.11.4.GIT