Class: Acter::Action
- Inherits:
-
Object
- Object
- Acter::Action
- Defined in:
- lib/acter/action.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(args, schema_data) ⇒ Action
constructor
A new instance of Action.
- #send_request(&block) ⇒ Object
Constructor Details
#initialize(args, schema_data) ⇒ Action
Returns a new instance of Action.
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 44 |
# File 'lib/acter/action.rb', line 10 def initialize(args, schema_data) @subject, @name = args.shift(2) @params = {} @headers = {} args.each_with_index do |arg, idx| case when /^(?<key>[^:=]+):(?<value>.*)/ =~ arg warn "Value of header #{key.inspect} is empty" if value.empty? @headers[key] = value when /^(?<key>[^:=]+)=(?<value>.*)/ =~ arg @params[key] = try_json_value(value) when idx.zero? @params[@subject] = try_json_value(arg) else raise ArgumentError, arg.inspect end end @schema, errors = JsonSchema.parse(schema_data) @schema or raise InvalidSchema.new("JSON schema parsing failed", errors) result, errors = @schema. result or raise InvalidSchema.new("JSON schema reference expansion failed", errors) @base_url = @schema.links.find do |li| li.href && li.rel == "self" end.try(:href) @base_url or raise InvalidSchema, "Schema has no valid link to self" validate_link! if Acter.help_wanted? raise HelpWanted.new(@name, @subject, @schema) end validate_params! end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def base_url @base_url end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def headers @headers end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def link @link end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def path @path end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def schema @schema end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
46 47 48 |
# File 'lib/acter/action.rb', line 46 def subject @subject end |