Module: Predicated

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

Overview

Procs and lambdas are “callable objects”

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.2.6"
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
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/predicated/gem_check.rb', line 2

def self.require_gem_version(gem_name, minimum_version, require_name=gem_name)
  gem_version = Gem::Requirement.create(">= #{minimum_version}")
  gem_found =
  if Gem::Specification.respond_to? :find_by_name
    # RubyGems 1.8
    Gem::Specification.find_by_name(gem_name, gem_version)
  else
    # RubyGems <= 1.7
    Gem.available?(gem_name, gem_version)
  end

  unless gem_found

    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/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/simple_templated_predicate.rb', line 5

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