Class: INat::Entity::Request
- Inherits:
-
Data::Entity
- Object
- Data::Model
- Data::Entity
- INat::Entity::Request
- Includes:
- INat::Entity
- Defined in:
- lib/inat/data/entity/request.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#observations ⇒ Array<item_type: Observation>
The
observations
field. -
#project ⇒ type: Project
The
project
field. -
#query ⇒ type: String
The
query
field. -
#time ⇒ type: Time
The
time
field.
Attributes inherited from Data::Entity
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id) ⇒ Request
constructor
A new instance of Request.
Methods inherited from Data::Entity
by_id, #complete?, ddl, fetch, from_db_rows, #get, #init, load, load_file, parse, read, #save, #to_db, #update
Methods included from App::Logger::DSL
#debug, debug, echo, #echo, error, #error, #info, info, log, #log, #warning, warning
Methods inherited from Data::Model
api_limit, api_part, api_path, backs, block, field, fields, has_path?, has_table?, #ignore, links, #post_update, #process?, #saved?, table, #to_h, #update
Constructor Details
#initialize(id) ⇒ Request
Returns a new instance of Request.
57 58 59 60 |
# File 'lib/inat/data/entity/request.rb', line 57 def initialize id super(id) @active = false end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
55 56 57 |
# File 'lib/inat/data/entity/request.rb', line 55 def active @active end |
#observations ⇒ Array<item_type: Observation>
Returns the observations
field.
24 |
# File 'lib/inat/data/entity/request.rb', line 24 links :observations, item_type: Observation, index: true |
#project ⇒ type: Project
Returns the project
field.
22 |
# File 'lib/inat/data/entity/request.rb', line 22 field :project, type: Project, index: true |
#query ⇒ type: String
Returns the query
field.
20 |
# File 'lib/inat/data/entity/request.rb', line 20 field :query, type: String, unique: true |
Class Method Details
.create(query_string, project_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inat/data/entity/request.rb', line 36 def create query_string, project_id update do max_id = DB.execute("SELECT max(id) AS id FROM requests;").map{ |r| r['id'] }.first new_id = if max_id == nil 1 else max_id + 1 end @entities ||= {} @entities[new_id] ||= new new_id @entities[new_id].time = Time::at(0) @entities[new_id].query = query_string @entities[new_id].project_id = project_id @entities[new_id].save end end |
.DDL ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/inat/data/entity/request.rb', line 28 def DDL super + "CREATE VIEW IF NOT EXISTS project_observations AS\n" + " SELECT r.project_id, ro.observation_id\n" + " FROM requests r, request_observations ro\n" + " WHERE r.id = ro.request_id AND r.project_id IS NOT NULL;\n" end |