Module: Predicated

Defined in:
lib/predicated/lib/predicated/from/callable_object.rb,
lib/predicated/lib/predicated/print.rb,
lib/predicated/lib/predicated/to/xml.rb,
lib/predicated/lib/predicated/to/arel.rb,
lib/predicated/lib/predicated/to/json.rb,
lib/predicated/lib/predicated/to/solr.rb,
lib/predicated/lib/predicated/version.rb,
lib/predicated/lib/predicated/evaluate.rb,
lib/predicated/lib/predicated/from/xml.rb,
lib/predicated/lib/predicated/constrain.rb,
lib/predicated/lib/predicated/from/json.rb,
lib/predicated/lib/predicated/gem_check.rb,
lib/predicated/lib/predicated/predicate.rb,
lib/predicated/lib/predicated/selectable.rb,
lib/predicated/lib/predicated/to/sentence.rb,
lib/predicated/lib/predicated/autogen_call.rb,
lib/predicated/lib/predicated/string_utils.rb,
lib/predicated/lib/predicated/from/url_part.rb,
lib/predicated/lib/predicated/from/ruby_code_string.rb,
lib/predicated/lib/predicated/simple_templated_predicate.rb

Overview

Procs and lambdas are “callable objects”

Defined Under Namespace

Modules: Container, ContainerSentence, ContainerToString, ContainerToXml, JsonStructToJsonStr, PrintSupport, Selectable, Shorthand, SimpleTemplatedShorthand, StringUtils, TreetopUrlPart Classes: And, AutogenCall, Binary, Call, Constraint, ConstraintCheckResult, Constraints, Equal, GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo, Not, Operation, Or, Placeholder, Predicate, Unary

Constant Summary collapse

VERSION =
"0.1.0"
ALL_PREDICATE_CLASSES =
[
  And, Or, Not, 
  Equal, LessThan, GreaterThan, LessThanOrEqualTo, GreaterThanOrEqualTo
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.require_gem_version(gem_name, minimum_version, require_name = gem_name) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/predicated/lib/predicated/gem_check.rb', line 2

def self.require_gem_version(gem_name, minimum_version, require_name=gem_name)
  unless Gem.available?(gem_name, Gem::Requirement.create(">= #{minimum_version}"))
    raise %{
Gem: #{gem_name} >=#{minimum_version}
Does not appear to be installed.  Please install it.

Predicated is built in a way that allows you to pick and 
choose which features to use.

RubyGems has no way to specify optional dependencies,
therefore I've made the decision not to have Predicated
automatically depend into the various gems referenced
in from/to "extensions".

The cost here is that the gem install doesn't necessarily 
"just work" for you out of the box.  But in return you get 
greater flexibility.  

Notably, rails/arel unfortunately has a hard dependency 
on Rails 3 activesupport, which requires ruby 1.8.7.  
By making from/to dependencies optional, those with 
no interest in arel can use Predicated in a wider 
variety of environments.

For more discussion see:
http://stackoverflow.com/questions/2993335/rubygems-optional-dependencies
}
  end
  
  require require_name
end

Instance Method Details

#Predicate(&block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/predicated/lib/predicated/predicate.rb', line 5

def Predicate(&block)
  result = nil
  Module.new do
    extend Shorthand
    result = instance_eval(&block)
  end
  result
end

#SimpleTemplatedPredicate(&block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/predicated/lib/predicated/simple_templated_predicate.rb', line 5

def SimpleTemplatedPredicate(&block)
  result = nil
  Module.new do
    extend SimpleTemplatedShorthand
    result = instance_eval(&block)
  end
  result
end