Class: UserQuery::Parameters
- Inherits:
-
Object
- Object
- UserQuery::Parameters
show all
- Defined in:
- lib/user_query/parameters.rb
Defined Under Namespace
Classes: Errors
Constant Summary
collapse
- @@active_record_errors =
Errors
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*opts) ⇒ Parameters
Returns a new instance of Parameters.
39
40
41
42
|
# File 'lib/user_query/parameters.rb', line 39
def initialize(*opts)
@hash = opts.empty? ? {} : opts[0]
@hash ||= { }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/user_query/parameters.rb', line 74
def method_missing(method, *args)
m = method.to_s.clone
if m.sub!(/=$/, '') && args.size == 1
$stderr.puts "set #{method.inspect} #{args[0].inspect}" if @verbose
result = @hash[m.intern] = args[0]
elsif m.sub!(/_before_type_cast$/, '') && args.size == 0
$stderr.puts "get #{method.inspect}" if @verbose
result = @hash[m.intern]
elsif args.size == 0
$stderr.puts "get #{method.inspect}" if @verbose
result = @hash[method]
else
raise NotImplementedError, method
end
result
end
|
Class Method Details
.human_attribute_name(x) ⇒ Object
53
54
55
|
# File 'lib/user_query/parameters.rb', line 53
def self.human_attribute_name(x)
x end
|
Instance Method Details
#[](key) ⇒ Object
58
59
60
|
# File 'lib/user_query/parameters.rb', line 58
def [](key)
@hash[key]
end
|
#_value_hash ⇒ Object
44
45
46
|
# File 'lib/user_query/parameters.rb', line 44
def _value_hash
@hash
end
|
#errors ⇒ Object
Emulate ActiverRecord::Base errors support
49
50
51
52
|
# File 'lib/user_query/parameters.rb', line 49
def errors
@errors ||= @@active_record_errors.new(self)
end
|
#id ⇒ Object
63
64
65
|
# File 'lib/user_query/parameters.rb', line 63
def id
@hash[:id]
end
|
#id=(x) ⇒ Object
66
67
68
|
# File 'lib/user_query/parameters.rb', line 66
def id=(x)
@hash[:id] = x
end
|
#respond_to?(meth) ⇒ Boolean
70
71
72
|
# File 'lib/user_query/parameters.rb', line 70
def respond_to?(meth)
true
end
|