Module: Mirage::Template::Model::InstanceMethods
- Extended by:
- Helpers::MethodBuilder
- Includes:
- CommonMethods
- Included in:
- Mirage::Template
- Defined in:
- lib/mirage/client/template/model/instance_methods.rb
Instance Attribute Summary collapse
-
#caller_binding ⇒ Object
Returns the value of attribute caller_binding.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #encode(value) ⇒ Object
- #encode_regexs(hash_or_array) ⇒ Object
- #initialize(*args) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #to_json ⇒ Object
Methods included from Helpers::MethodBuilder
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 82 def method_missing(method, *args, &block) if @caller_binding @caller_binding.send method, *args, &block else super method, *args, &block end end |
Instance Attribute Details
#caller_binding ⇒ Object
Returns the value of attribute caller_binding.
8 9 10 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 8 def caller_binding @caller_binding end |
Instance Method Details
#create ⇒ Object
34 35 36 37 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 34 def create @id = self.class.put("#{@endpoint}", :body => self.to_json, :headers => {'content-type' => 'application/json'})['id'] self end |
#delete ⇒ Object
39 40 41 42 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 39 def delete self.class.delete(url) Request.delete requests_url end |
#encode(value) ⇒ Object
78 79 80 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 78 def encode(value) value.is_a?(Regexp) ? "%r{#{value.source}}" : value end |
#encode_regexs(hash_or_array) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 65 def encode_regexs hash_or_array case hash_or_array when Array hash_or_array.collect { |value| encode(value) } else encoded = {} hash_or_array.each do |key, value| encoded[key] = encode(value) end encoded end end |
#initialize(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 10 def initialize *args if args.last.is_a?(Template::Configuration) default_config = args.delete_at(-1) else default_config = Template::Configuration.new end @endpoint, @body = *args @content_type = default_config.content_type @http_method = default_config.http_method @status = default_config.status @delay = default_config.delay @required_parameters = {} @required_headers = {} @required_body_content = [] @headers = {} @default = default_config.default end |
#to_json ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mirage/client/template/model/instance_methods.rb', line 45 def to_json { :response => { :body => Base64.encode64(body), :status => status, :default => default, :content_type => content_type, :headers => headers, :delay => delay }, :request => { :parameters => encode_regexs(required_parameters), :headers => encode_regexs(required_headers), :body_content => encode_regexs(required_body_content), :http_method => http_method, } }.to_json end |