Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating packaging and verified tests under 1.9.2, 1.9.3 and 2.0.0 ru…

…bies and respective actionpacks
  • Loading branch information...
commit 2551eae2b41bf3c1cf096bbe3bb179c84583a66d 1 parent cdce75a
@coldnebo authored
View
15 Gemfile
@@ -1,16 +1,7 @@
# this file is provided in case you wish to setup a development environment for the gem quickly
# using 'bundle install'. It is not a requirement of using the gem itself.
-source :rubygems
+source 'https://rubygems.org'
-group :test do
- #gem 'debugger'
- gem 'simplecov', :require => false
- gem 'mocha'
- gem 'actionpack', '2.3.11'
-end
-
-group :development do
- gem 'yard'
- gem 'redcarpet'
-end
+# Specify your gem's dependencies in data_hut.gemspec
+gemspec
View
50 Rakefile
@@ -1,49 +1,11 @@
-require 'rubygems/package_task'
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
require 'rake/testtask'
-require 'yard'
-
-
-PKG_VERSION = '0.0.8'
-
-SRC_FILES = Dir.glob('lib/**/*')
-TST_FILES = Dir.glob('test/**/*')
-EXTRA_DOC_FILES = ["README.md", "MIT-LICENSE"]
-
-
-PKG_FILES = [SRC_FILES, EXTRA_DOC_FILES].flatten
-
-spec = Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
-
- s.version = PKG_VERSION
- s.requirements << 'rails'
- #s.add_dependency('rails')
- s.require_path = 'lib'
-
- s.files = PKG_FILES
- s.test_files = TST_FILES
- s.description = "Conditional UI predicates for Rails - a clean and simple approach to separate business logic from your views and models."
-
- s.name = 'condi'
- s.date = '2012-06-14'
- s.summary = "Condi"
- s.authors = ["Larry Kyrala"]
- s.email = 'larry.kyrala@gmail.com'
- s.homepage = 'http://github.com/coldnebo/condi'
- s.has_rdoc = 'yard'
-
-end
-
-Gem::PackageTask.new(spec) do |pkg|
-end
-
-YARD::Rake::YardocTask.new do |t|
- t.files = [SRC_FILES, '-', EXTRA_DOC_FILES].flatten # optional
-end
Rake::TestTask.new do |t|
- t.libs << 'test'
+ t.libs << 'lib'
+ t.test_files = FileList['test/test*.rb']
+ t.verbose = true
end
-
-desc "Run tests"
task :default => :test
+
View
26 condi.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/condi/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Larry Kyrala"]
+ gem.email = ["larry.kyrala@gmail.com"]
+ gem.description = %q{Conditional UI predicates for Rails - a clean and simple approach to separate business logic from your views and models.}
+ gem.summary = %q{Lightweight rules engine for Rails}
+ gem.homepage = "https://github.com/coldnebo/condi"
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "condi"
+ gem.require_paths = ["lib"]
+ gem.version = Condi::VERSION
+
+ gem.add_dependency 'actionpack'
+
+ gem.add_development_dependency 'mocha'
+ gem.add_development_dependency 'pry'
+ gem.add_development_dependency 'yard'
+ gem.add_development_dependency 'redcarpet'
+ gem.add_development_dependency 'simplecov'
+
+end
View
67 lib/condi.rb
@@ -1,65 +1,2 @@
-# Include this module in an ActionController to define predicates or synonyms within an action context that
-# can be used later in the related action view.
-# @example
-# class StoreController
-# include Condi
-# ...
-# end
-module Condi
-
- # define a method on the controller which is callable from the related view and returns a true or false value.
- # @example define a predicate that determines whether or not to show a "free shipping" option.
- # predicate(:show_free_shipping?) { user.new_customer? && cart.amount > 100 }
- # @example define a predicate that takes an element of a collection as an argument.
- # predicate(:shipping?) { |item| @items.count >= 3 &&
- # item.status == :shipped &&
- # DeliveryService.status(item.tracking_number) !~ /arrived/ }
- # @example define a synonym that returns a css class based on item status
- # synonym(:css_for_item_status) do |item|
- # if @items.count >= 3 && item.status == :shipped
- # if DeliveryService.status(item.tracking_number) !~ /arrived/
- # "shipping"
- # else
- # "shipped"
- # end
- # else
- # "processing"
- # end
- # end
- # @param [Symbol] method_name name of the predicate or synonym method. (e.g. :show_action_button?)
- # @param [Proc] block {} or do...end block.
- # @note A *synonym* is an alias for defining methods that return values other than true or false.
- # @note You are not required to end a predicate with a question mark, however it is conventional in Ruby to do so.
- # @note Predicates can only be called during the request scope they are defined in, otherwise a RuntimeError is raised. This restriction prevents the associated closures from inadvertently leaking previous request data when the controller classes are cached (i.e. in production).
- # @note Predicates are semantically lambdas and may contain returns.
- # @see the full example in the <a href="index.html">README</a>.
- def predicate(method_name, &block)
- self.class.instance_eval do
- # this is the request id at the moment the predicate is defined
- request_id = eval("request.object_id",block.binding)
-
- # We need to keep the block impl as a method/lambda so that it supports returns
- # by using this particular invocation of define_method...
- method_name_impl = "impl_#{method_name}".to_sym
- define_method(method_name_impl, &block)
-
- # Next, this invocation of define_method creates a Proc, which
- # wraps the impl and allows us to check the request id.
- define_method(method_name) do |*args|
- # this is the request id at the moment the predicate is called
- check_request_id = request.object_id
- # if they don't match, raise an error!
- unless check_request_id == request_id
- raise RuntimeError, "predicate '#{method_name}' cannot be called outside of the request scope it was defined in (#{request_id}). please redefine the predicate in this request scope (#{check_request_id}).", caller(2)
- end
- send(method_name_impl, *args)
- end
-
- # finally, expose the wrapped predicate to the view.
- helper_method(method_name)
- end
- end
-
- # a synonym can be used to define methods that return values besides true and false.
- alias_method :synonym, :predicate
-end
+require "condi/version"
+require "condi/condi"
View
65 lib/condi/condi.rb
@@ -0,0 +1,65 @@
+# Include this module in an ActionController to define predicates or synonyms within an action context that
+# can be used later in the related action view.
+# @example
+# class StoreController
+# include Condi
+# ...
+# end
+module Condi
+
+ # define a method on the controller which is callable from the related view and returns a true or false value.
+ # @example define a predicate that determines whether or not to show a "free shipping" option.
+ # predicate(:show_free_shipping?) { user.new_customer? && cart.amount > 100 }
+ # @example define a predicate that takes an element of a collection as an argument.
+ # predicate(:shipping?) { |item| @items.count >= 3 &&
+ # item.status == :shipped &&
+ # DeliveryService.status(item.tracking_number) !~ /arrived/ }
+ # @example define a synonym that returns a css class based on item status
+ # synonym(:css_for_item_status) do |item|
+ # if @items.count >= 3 && item.status == :shipped
+ # if DeliveryService.status(item.tracking_number) !~ /arrived/
+ # "shipping"
+ # else
+ # "shipped"
+ # end
+ # else
+ # "processing"
+ # end
+ # end
+ # @param [Symbol] method_name name of the predicate or synonym method. (e.g. :show_action_button?)
+ # @param [Proc] block {} or do...end block.
+ # @note A *synonym* is an alias for defining methods that return values other than true or false.
+ # @note You are not required to end a predicate with a question mark, however it is conventional in Ruby to do so.
+ # @note Predicates can only be called during the request scope they are defined in, otherwise a RuntimeError is raised. This restriction prevents the associated closures from inadvertently leaking previous request data when the controller classes are cached (i.e. in production).
+ # @note Predicates are semantically lambdas and may contain returns.
+ # @see the full example in the <a href="index.html">README</a>.
+ def predicate(method_name, &block)
+ self.class.instance_eval do
+ # this is the request id at the moment the predicate is defined
+ request_id = eval("request.object_id",block.binding)
+
+ # We need to keep the block impl as a method/lambda so that it supports returns
+ # by using this particular invocation of define_method...
+ method_name_impl = "impl_#{method_name}".to_sym
+ define_method(method_name_impl, &block)
+
+ # Next, this invocation of define_method creates a Proc, which
+ # wraps the impl and allows us to check the request id.
+ define_method(method_name) do |*args|
+ # this is the request id at the moment the predicate is called
+ check_request_id = request.object_id
+ # if they don't match, raise an error!
+ unless check_request_id == request_id
+ raise RuntimeError, "predicate '#{method_name}' cannot be called outside of the request scope it was defined in (#{request_id}). please redefine the predicate in this request scope (#{check_request_id}).", caller(2)
+ end
+ send(method_name_impl, *args)
+ end
+
+ # finally, expose the wrapped predicate to the view.
+ helper_method(method_name)
+ end
+ end
+
+ # a synonym can be used to define methods that return values besides true and false.
+ alias_method :synonym, :predicate
+end
View
3  lib/condi/version.rb
@@ -0,0 +1,3 @@
+module Condi
+ VERSION = "1.0.0"
+end
View
3  lib/version.rb
@@ -0,0 +1,3 @@
+module Condi
+ VERSION = "0.0.8"
+end
View
2  test/test_condi.rb
@@ -2,7 +2,7 @@
SimpleCov.start
require 'test/unit'
-require 'mocha'
+require 'mocha/setup'
require 'action_controller'
require 'condi'
Please sign in to comment.
Something went wrong with that request. Please try again.