Class: MicroSqlUser
- Inherits:
-
Object
- Object
- MicroSqlUser
- Defined in:
- lib/spec/virtualizees/micro_sql_dsl.rb
Instance Method Summary collapse
-
#select_complex ⇒ Object
Should turn into: def select_complex name_is_rahul = “name="rahul"” right_id = “id=5” is_full_name = “name="Rahul Rajagopalan"” VirtualKeywords::REWRITTEN_KEYWORDS.call_if( self, lambda do VirtualKeywords::REWRITTEN_KEYWORDS.call_or( self, lambda do VirtualKeywords::REWRITTEN_KEYWORDS.call_and( self, lambda { name_is_rahul }, lambda { right_id } ) end, lambda { is_full_name } ) end, lambda { Sql.select([:name, :post_ids], :from => :users) }, lambda { } ) end.
-
#select_with_or ⇒ Object
Should turn into: def select_with_or name_is_rahul = “name="rahul"” is_full_name = “name="Rahul Rajagopalan"” VirtualKeywords::REWRITTEN_KEYWORDS.call_if( self, lambda do VirtualKeywords::REWRITTEN_KEYWORDS.call_or( self, lambda { name_is_rahul }, lambda { is_full_name } ) end, lambda { Sql.select([:name, :post_ids], :from => :users) }, lambda { } ) end.
-
#select_with_where ⇒ Object
Ok, now mix in some VirtualKeywords! Use postfix “if” to stand in for “where” clauses.
-
#simple_select ⇒ Object
First version, just using built-in syntatic sugar: optional parentheses and braces around hashes.
Instance Method Details
#select_complex ⇒ Object
Should turn into: def select_complex
name_is_rahul = "name=\"rahul\""
right_id = "id=5"
is_full_name = "name=\"Rahul Rajagopalan\""
VirtualKeywords::REWRITTEN_KEYWORDS.call_if(
self,
lambda do
VirtualKeywords::REWRITTEN_KEYWORDS.call_or(
self,
lambda do
VirtualKeywords::REWRITTEN_KEYWORDS.call_and(
self,
lambda { name_is_rahul },
lambda { right_id }
)
end,
lambda { is_full_name }
)
end,
lambda { Sql.select([:name, :post_ids], :from => :users) },
lambda { }
)
end
103 104 105 106 107 108 109 |
# File 'lib/spec/virtualizees/micro_sql_dsl.rb', line 103 def select_complex name_is_rahul = 'name="rahul"' right_id = 'id=5' is_full_name = 'name="Rahul Rajagopalan"' Sql::select [:name, :post_ids], :from => :users if name_is_rahul and right_id or is_full_name end |
#select_with_or ⇒ Object
Should turn into: def select_with_or
name_is_rahul = "name=\"rahul\""
is_full_name = "name=\"Rahul Rajagopalan\""
VirtualKeywords::REWRITTEN_KEYWORDS.call_if(
self,
lambda do
VirtualKeywords::REWRITTEN_KEYWORDS.call_or(
self,
lambda { name_is_rahul },
lambda { is_full_name }
)
end,
lambda { Sql.select([:name, :post_ids], :from => :users) },
lambda { }
)
end
72 73 74 75 76 77 |
# File 'lib/spec/virtualizees/micro_sql_dsl.rb', line 72 def select_with_or name_is_rahul = 'name="rahul"' is_full_name = 'name="Rahul Rajagopalan"' Sql::select [:name, :post_ids], :from => :users if name_is_rahul or is_full_name end |
#select_with_where ⇒ Object
Ok, now mix in some VirtualKeywords! Use postfix “if” to stand in for “where” clauses. It should look gramatically similar to SQL, just with “if” instead of “where”.
Calling virtual_if should turn this method into:
name_is_rahul = ‘name=“rahul”’ VirtualKeywords::REWRITTEN_KEYWORDS.call_if(
self,
lambda { Sql::select [:name, :post_ids], :from=> :users },
lambda { name_is_rahul },
lambda {}
)
45 46 47 48 49 50 51 52 53 |
# File 'lib/spec/virtualizees/micro_sql_dsl.rb', line 45 def select_with_where # Limitation: 'name="rahul"' is in quotes (we can't actually get # AST nodes because virtual_keywords hides them.) # Using the string literal directly is valid Ruby, but produces # an annoying warning. name_is_rahul = 'name="rahul"' Sql::select [:name, :post_ids], :from => :users if name_is_rahul end |
#simple_select ⇒ Object
First version, just using built-in syntatic sugar: optional parentheses and braces around hashes.
26 27 28 29 30 |
# File 'lib/spec/virtualizees/micro_sql_dsl.rb', line 26 def simple_select # Limitation: the parser can't handle the new hash syntax # (so here we use the old one) Sql::select [:name, :post_ids], :from => :users end |